Posted By

jaytee on 04/09/08


Tagged

regex url pregreplace


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Folio
mitchkramez
zeljic


Replace a URL with its domain name and create link


 / Published in: PHP
 

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]"

  1. preg_replace("/http:\/\/([^\/]+)[^\s]*/", "<a href='$0'>$1</a>", $text);

Report this snippet  

You need to login to post a comment.