Skip to content

Instantly share code, notes, and snippets.

@ellisio
Created July 20, 2017 04:38
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 ellisio/1c6da4c8b3fa401d9ac66da9a3a20ce2 to your computer and use it in GitHub Desktop.
Save ellisio/1c6da4c8b3fa401d9ac66da9a3a20ce2 to your computer and use it in GitHub Desktop.
$ 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