Forum Moderators: coopster
$URL = "http://www.site.com/venue/id";
$Contents = file_get_contents($URL);
$Lines = preg_split("/\n/",$Contents);
foreach($Lines as $Line)
{
if (preg_match("/([^`]*?), Chicago, IL /",$Line,$Match))
{
print("Found match (" . $Match[1] . ")<br />\n");
}
}
I thought that would return all the lines that had Chicago, IL in it and whatever text preceded it but instead it returns nothing.
Thanks for any help you can give me.
$matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
So your $Match[1] will contain any text that doesn't have a back-quote (`) in it that precedes ', Chicago, IL '. Given that you're dealing with HTML, I wouldn't use bare spaces like that, but replace them with \s* or \s+. Also are you sure that the address and city are actually on the same line?