我有一个preg_match_all模式来捕捉只有货币符号的数字,或者如果没有符号,只是数字。但是,除了没有符号的$符号之外,它会失败(不返回任何错误)。Preg_match_all失败
这里就是我想:
include 'simple_html_dom.php';
$html = file_get_html($url);
// Find price if added our code
$ret = $html->find('.price');
$pattern = '/\p{Sc}\s*\d{1,3}(?:,\d{3})*(?:\.\d+)?/u';
以下是什么可能由simple_html_dom以及他们是否工作或失败返回的例子 - 它可能是以下
$ret[0] = '<span class="price">100</span>'; // this returns null
$ret[0] = '<span class="price">£100</span>'; // this returns null
$ret[0] = '<span class="price">€100</span>'; // this returns null
$ret[0] = '<span class="price">$100</span>'; // this works correctly and returns $100
preg_match_all($pattern, $ret[0], $matches);
echo $matches[0][0];
ONE任何想法为什么?
你似乎是使用DOM解析器......为什么以后使用正则表达式来解析HTML? –