I have this text:
$string = \"this is my friend\'s website http://example.com I think it is coll\";
How can I extract the link into another
The code that worked for me (especially if you have several links in your $string) is:
$string = "this is my friend's website https://www.example.com I think it is cool, but this one is cooler https://www.stackoverflow.com :)";
$regex = '/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i';
preg_match_all($regex, $string, $matches);
$urls = $matches[0];
// go over all links
foreach($urls as $url)
{
echo $url.'
';
}
Hope that helps others as well.