Posted By

global_1981 on 04/29/11


Tagged

php twitter


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

freaktheclown


Twitter Linkify (PHP)


 / Published in: PHP
 

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

linkify twitter text status

  1. function linkify_twitter_status($status_text)
  2. {
  3. // linkify URLs
  4. $status_text = preg_replace(
  5. '/(https?:\/\/\S+)/',
  6. '<a href="\1">\1</a>',
  7. $status_text
  8. );
  9.  
  10. // linkify twitter users
  11. $status_text = preg_replace(
  12. '/(^|\s)@(\w+)/',
  13. '\1@<a href="http://twitter.com/\2">\2</a>',
  14. $status_text
  15. );
  16.  
  17. // linkify tags
  18. $status_text = preg_replace(
  19. '/(^|\s)#(\w+)/',
  20. '\1#<a href="http://search.twitter.com/search?q=%23\2">\2</a>',
  21. $status_text
  22. );
  23.  
  24. return $status_text;
  25. }

Report this snippet  

You need to login to post a comment.