$pattern = '/((?:https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$])/i';
if(preg_match_all($pattern, $string, $match)) {
$string=$match[0][0];
echo $string;
}
I came up with that using preg_match_all. It's almost what I want.
$string = "<a href="http://google.com">Google</a> this is some text http://yahoo.com this is some texthttp://msn.com";
If the string was what I have above, how do I make the pattern stop at a " or '. Otherwise the first string produced would be http://google.com">Google</a>. I just want it to be http://google.com. It only stops at the first space. I would like it to stop at the first space, the first ", or the first '.
So I would want the output of $string=$match[0][0] to be http://google.com. The output of $string=$match[0][1] to be http://yahoo.com, and so on.