Advertisement
ssaidz

Links to Hyperlinks (Auto)

Jul 8th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2. function makeClickableLinks($text) {
  3. $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&amp;//=]+)','&lt;a href="\\1"&gt;\\1&lt;/a&gt;', $text);
  4. $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&amp;//=]+)','\\1&lt;a href="http://\\2"&gt;\\2&lt;/a&gt;', $text);
  5. $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','&lt;a href="mailto:\\1"&gt;\\1&lt;/a&gt;', $text);
  6. return $text;
  7. }
  8. // Usage
  9. // Email address example
  10. $text = "you@example.com";
  11. echo makeClickableLinks($text);
  12. echo "&lt;br /&gt;&lt;br /&gt;";
  13. // URL example
  14. $text = "http://www.saidz.info";
  15. echo makeClickableLinks($text);
  16. echo "&lt;br /&gt;&lt;br /&gt;";
  17. // FTP URL example
  18. $text = "ftp://ftp.saidz.info";
  19. echo makeClickableLinks($text);
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement