php text to link


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.