Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$ art tinker
Psy Shell v0.8.8 (PHP 7.1.6 — cli) by Justin Hileman
>>> $url = '@(http)?(s)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@';
=> "@(http)?(s)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@"
>>> $string = 'superawesome.com';
=> "superawesome.com"
>>> $string = preg_replace($url, '<a href="http$2://$4" target="_blank" title="$0">$0</a>', $string);
=> "<a href="https://uperawesome.com" target="_blank" title="superawesome.com">superawesome.com</a>"
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.