0

I want the string FC Barcelona v BM Huesc , FC Ferrari v BM ameriF and C semari v AM buhari from below code.

$mat = '<font color="white">FC Barcelona v BM Huesca

<font color="white">FC Ferrari v BM ameri

<font color="white">FC semari v AM buhari
';

I tried below code , but it does not seems to work.Any help will be appreciated.Thanks

preg_match_all('/<font color="white">(.*?)/',$mat,$mats);
var_dump($mats);

Edit: My real time example is below

<?php
$game = file_get_contents("http://www.firstrow1.eu/bet365/index.html");
preg_match_all('/<\/td><td><font color="white">(.*)/m',$game,$mats);
var_dump($mats);
?>

2 Answers2

2

.*? will match nothing because it is relucant and matches as little as possible. Since there is no other part of the expression after it, it is done when it has matched nothing. Use .* because with all its greediness it will only match up to the end of the line. Note that this is true regardless of whether you use the m modifier or not.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0
preg_match_all("#<font color=\"white\">(.*?)\n#si", $mat, $mats);

It works!

mkjasinski
  • 3,115
  • 2
  • 22
  • 21
  • 1
    There's no real benefit to enabling single-line mode since your non-greedy dot-star followed by a newline will stop at the first newline in the target string anyway. – Kenneth K. Mar 18 '13 at 16:03