Posted By

metoikos on 06/13/10


Tagged

regex php link text


Versions (?)

php text to link


 / Published in: PHP
 

  1. function replace_plain_text_link($plain_text) {
  2. $url_html = preg_replace(
  3. '/(?<!S)((http(s?):\/\/)|(www.))+([\w.1-9\&=#?\-~%;\/]+)/',
  4. '<a href="http$3://$4$5">http$3://$4$5</a>', $plain_text);
  5. return ($url_html);
  6. }
  7. echo replace_plain_text_link("hi this is dummy text before
  8. http://www.smjdesign.com hi this is dummy text after")

Report this snippet  

You need to login to post a comment.