Replace a URL with its domain name and create link

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

Worst title ever. Basically, this takes a string like:
"Check this out:" and replaces it with "Check this out: [with a link to the full URL]"

Copy this code and paste it in your HTML
  1. preg_replace("/http:\/\/([^\/]+)[^\s]*/", "<a href='$0'>$1</a>", $text);

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.