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: http://snipplr.com/view/5759/replace-a-url-its-domain-name-and-create-link/" and replaces it with "Check this out: snipplr.com [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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.