Reputation: 643
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
Upvotes: 1
Views: 109
Reputation: 343
'<span class="c_value">(.*?)<\/span>/s';
or try
if(preg_match('/<span class="c_name">.*?EUR<\/span> <span class="c_value">(.*?)<\/span>/mis', $rawresult, $result))
Upvotes: 0
Reputation: 1709
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))
Upvotes: 0
Reputation: 11375
You don't need a regular expression for this, you can just use filter_var
with a specific flag to allow the thousands
echo filter_var('<span class="c_name">€ EUR</span> <span class="c_value">1,9110</span>', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
Upvotes: 3