Advertisement
Guest User

Best way to make links clickable in block of text

a guest
Mar 24th, 2012
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. Here is link: http://google.com
  2. And http://example.com inside.
  3. And another one at the very end: http://test.net
  4.  
  5. Here is link: <a href="http://google.com">http://google.com</a>
  6. And <a href="http://example.com">http://example.com</a> inside.
  7. And another one at the very end: <a href="http://test.net">http://test.net</a>
  8.  
  9. function make_links_clickable($text){
  10. // ???
  11. }
  12.  
  13. $text = 'Here is link: http://google.com
  14. And http://example.com inside.
  15. And another one at the very end: http://test.net';
  16.  
  17. echo make_links_clickable($text);
  18.  
  19. function make_links_clickable($text){
  20. return preg_replace('!(((f|ht)tp://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $text);
  21. }
  22.  
  23. function make_links_clickable($text)
  24. {
  25. return preg_replace ('/http://[^s]+/i', "<a href="${0}">${0}</a>", $text);
  26. }
  27.  
  28. $result = function make_links_clickable($text);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement