Search code examples
phpregexpreg-match

php preg match parse html


I am trying to get 1,9110 from the string:

<span class="c_name">€ EUR</span> <span class="c_value">1,9110</span>

And my code is:

// EUR //
if(preg_match('/<span class="c_name">€ EUR<\/span> <span class="c_value">(.*?)<\/span>/mis', $rawresult, $result))
{
    $banks['access']['sale']['EUR'] = $result[1];
} else {
    $banks['access']['sale']['EUR'] = false;
}
var_dump($banks);
// EUR //

But this code isn't working


Solution

  • Your regex crashes on the euro-sign. Try to escape it like this:

    if(preg_match('/<span class="c_name">\x{20AC} EUR<\/span> <span class="c_value">(.*?)<\/span>/misu', $rawresult, $result))