Posted By

yazu on 12/19/09


Tagged

php link text regular Expression convert


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

redstorm


Convert text to link


 / Published in: PHP
 

  1. <?php
  2. function convertToURL($text) {
  3. $text = preg_replace("/([a-zA-Z]+:\/\/[a-z0-9\_\.\-]+"."[a-z]{2,6}[a-zA-Z0-9\/\*\-\_\?\&\%\=\,\+\.]+)/"," <a href=\"$1\" target=\"_blank\">$1</a>", $text);
  4. $text = preg_replace("/[^a-z]+[^:\/\/](www\."."[^\.]+[\w][\.|\/][a-zA-Z0-9\/\*\-\_\?\&\%\=\,\+\.]+)/"," <a href="\\" target="\">$1</a>", $text);
  5. $text = preg_replace("/([\s|\,\>])([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-z" . "A-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})" . "([A-Za-z0-9\!\?\@\#\$\%\^\&\*\(\)\_\-\=\+]*)" . "([\s|\.|\,\<])/i", "$1<a href=\"mailto:$2$3\">$2</a>$4", $text);
  6.  
  7. return $text;
  8. }
  9. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: scvinodkumar on December 21, 2009

excellent

You need to login to post a comment.