我有一個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? –