Created
December 31, 2012 06:15
-
-
Save nickleefly/4417783 to your computer and use it in GitHub Desktop.
url to clickable link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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