This post is over a year old, some of this information may be out of date.
Let's say I have a string coming from text box by users (maybe a comment box or something similar), and when displaying that text into another screen I would like that the URLs inside that text to be clickable. How I would I do that in PHP ? I have found you can use something like this:
$text = "Please visit http://google.com and also https://yahoo.com";
$html_links = preg_replace('"\b(https?://\S+)"', '<a href="$1" target="_blank">$1</a>', $text);
echo $html_links;
And this would work for both http and https URLs 🎉