View Full Version : Having problem with preg_match

05-05-2009, 01:35 PM
Can anyone tell me why I am not just getting the URL from the below code returned in $matches[1]..... The returned URL starts correctly, but it also includes a ton of data after the closing quotes after the URL portion is finished.

if (preg_match('~</script><br /><br /><a href="(.+)" class="link" target="_blank">~i',$html,$match)) {
// blah


05-05-2009, 01:42 PM
Probably because your regexp is greedy. Try (.+?) instead of (.+), or put the modifier U at the end of your regexp.

05-05-2009, 03:02 PM
Thanks..... I actually changed it to the below..

if (preg_match('~</script><br /><br /><a href="([^"]+)" class="link" target="_blank">~i',$html,$match)) {
// blah

Dunno why I didn't notice that earlier. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum