Created
May 6, 2024 13:46
-
-
Save moriarty99779/76aa36574442d8e70995c8df77bec714 to your computer and use it in GitHub Desktop.
PHP Turn a URL inside of a string into a 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
function linkify_string ($stringwithurl) { | |
return "<p>" . preg_replace('!(http|ftp|scp)(s)?:\/\/[a-zA-Z0-9.?&_\-\=/]+!', "<a target='_blank' href=\"\\0\">\\0</a>", $stringwithurl) . "</p>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment