Twitter Linkify (PHP)


/ Published in: PHP
Save to your folder(s)

linkify twitter text status


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.