ssaidz

Links to Hyperlinks (Auto)

Jul 8th, 2016
135
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. echo makeClickableLinks($text);
  11. echo "&lt;br /&gt;&lt;br /&gt;";
  12. // URL example
  13. $text = "http://www.saidz.info";
  14. echo makeClickableLinks($text);
  15. echo "&lt;br /&gt;&lt;br /&gt;";
  16. // FTP URL example
  17. $text = "ftp://ftp.saidz.info";
  18. echo makeClickableLinks($text);
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment