0

I am using file_get_contents from a site that has data like this (I have copied only a bit of it):

<TD class=cellres align=left><a href=results.php?team=Wolves&league=EngPrem>Wolves</a></TD> <TD class=cellres align=left><a href=results.php?team=Liverpool&league=EngPrem><b>Liverpool</b></a></TD>

Here is my preg_match code:

preg_match('/<TD class=cellres align=left><a href=results.php?team=.*&league=.*>(.*?)<\/TD> /',$contents,$home);
echo $home[1] . '<br>';

As you can see, I am using multiple wildcards, the "team=" needs a wildcard and the "league=" needs another wildcard, all data has different teams and different leagues. The data I want is "Wolves" which is just before the tag. The code above I am not sure what is wrong with it, as it is not displaying any data. Anyone know why?

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
Kevin
  • 51
  • 3
  • 13

1 Answers1

1

You haven't escaped special characters in your pattern. For the record, you will have better long term success with a dom parser e.g. DomDocument accompanied with Xpath.

This should fix you up.

/<TD class=cellres align=left><a href=results\.php\?team=[^>]*&league=[^>]*>(.*?)<\/a><\/TD>/
mickmackusa
  • 43,625
  • 12
  • 83
  • 136