Hey Leon -

There's code at the link below that has worked for me in the past. I
have since re-written it in JavaScript (using the same regular
expressions) as I'm now 'building' tweets for display on the client
side - but the expressions still work even in JS....

http://davidwalsh.name/linkify-twitter-feed

That code will show you how to create links from 1) Links, 2) Screen
Names and 3) Hashtags

I, personally, removed the following from the screen name and hashtag
expressions:  (^|\s)

...which means match the beginning of the line or a space - however, I
once saw a tweet that had this: .@screenname

...notice the period before the "@"? That's neither the beginning of
the line nor a space, and the code as-is didn't linkify it, even
though viewing the same tweet on twitter.com showed it as a link.
Removing the (^|\s) allowed it to be linkified, and you're not often
going to see an "@" or an "#" in a tweet that isn't a screen name or a
hashtag, so I think it's a fairly safe bet to take. Though, if anyone
ever puts, say, an email address in a tweet, it'll treat it as a
screen name if you don't have the (^|\s) in there...

Hope that helps!

On Feb 8, 11:26 pm, "Leon Meijer" <[email protected]> wrote:
> Hello all,  
>
> Just gave it a quick google but no results so far, i'm looking for a PHP 
> regular expression / script that scans a tweet for @ username, I'm not so 
> good at regular expressions so does someone have a sample code that scans for 
> @mentions and creates a URL to the users profile (which in my case will 
> behttp://beta.TheNerdsOnline.nl/users/usernamewhere username is the Twitter 
> screen_name).  
>
> Regards,  
>
> Leon

-- 
Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 
http://groups.google.com/group/twitter-development-talk

Reply via email to