Skip to content

Instantly share code, notes, and snippets.

@nickleefly
Created December 31, 2012 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickleefly/4417783 to your computer and use it in GitHub Desktop.
Save nickleefly/4417783 to your computer and use it in GitHub Desktop.
url to clickable link
<!--
a few lines of code to make a url into a clickable link
using lazy star (.*?) and $0
-->
<?php
$string = 'http://www.haha.com www.haha.com hahahaha https://www.haha.com';
$string = $string." ";
$stringall = preg_replace('/((https:\/\/)|(http:\/\/)|(www\.))(.*?)(?=\s)/i','<a href="$0" target="_blank">$0</a>',$string);
$stringallc = preg_replace('/(href=\"www\.)/i','href="http://www.',$stringall);
echo $stringallc;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment