Posted By

bgriffiths on 05/12/09


Tagged

url link twitter reply replies


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

danielfilho
nkrstevski
maxvee8
love
calvingilbert
polarbear
gripnrip
nb109
Josh
naphetz


Twitter @reply and urls to links


 / Published in: PHP
 

  1. $text = utf8_decode( $results[ $i ][ "text" ] );
  2. $text = preg_replace('@(https?://([-\w\.]+)+(d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text );
  3. $text = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://www.twitter.com/\\2\" >@\\2</a>'", $text);
  4. $text = preg_replace("#(^|[\n ])\#([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://hashtags.org/search?query=\\2\" >#\\2</a>'", $text);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jstgermain on June 28, 2009

dude, you are a genius, i love this. i as having a tough time getting my script to replace the @name with a link, and this solved that problem with a copy and paste. thanks.

You need to login to post a comment.