I'm using the following regex in PHP to grab the URLs from a string
regex = '/https?\:\/\/[^\" ]+/i';
$string = "lorem ipsum http://google.com lorem ipusm dolor http://yahoo.com/something";
preg_match_all($regex, $string, $matches);
$urls = ($matches[0]);
$urls
returns all the URLs. How can return only the first URL? In this case http://google.com
.
I'm trying to achieve this without using a foreach loop.