Skip to content

Instantly share code, notes, and snippets.

@funnylookinhat
Created April 17, 2013 18:16
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 funnylookinhat/5406491 to your computer and use it in GitHub Desktop.
Save funnylookinhat/5406491 to your computer and use it in GitHub Desktop.
RegEXP Find / Replace URLs with Links
<?php
// RegEXP
// @(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-\+]*(\?\S+)?[^\.\s])?)?)@
$string = "Whatever!";
$new_string = preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-\+]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $string );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment