user1548769
user1548769

Reputation: 319

file get contents preg_match

I am trying to find the correct string for preg_match in this situation

this is the data I am trying to scrape

  <td style="background-color:#FFFF66;font-weight:bold;">08/21/2013</td><td>

I just need the 08/21/2013 If I just print $file_string it prints the whole page fine its just when I try to pull out that date. I have a feeling it has to do with the quotes or slashes I have tried this and several other combos nogo

 preg_match("/bold;\">(.+)\<\/td><td>/i", $file_string, $matches);
$print = "$matches[1]";
 echo $print;

Upvotes: 0

Views: 1195

Answers (2)

Joni
Joni

Reputation: 111349

Regular expressions are greedy by default; they match as much as possible. You can use a reluctant modifier to match only as little as possible. Also, you don't need a backslash before a <.

preg_match("/bold;\">(.+?)<\/td><td>/i", $file_string, $matches);

Upvotes: 0

Vincent jaouen
Vincent jaouen

Reputation: 167

How about this?

preg_match("/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/", $file_string, $matches);

Upvotes: 1

Related Questions