Php简单html dom解析器查找包含任意字符的字符串
我有这个htmlPhp简单html dom解析器查找包含任意字符的字符串,php,html,parsing,Php,Html,Parsing,我有这个html <div class="price-box"> <p class="old-price"> <span class="price-label">This:</span> <span class="price" id="old-price-326"> 8,69 € </sp
<div class="price-box">
<p class="old-price">
<span class="price-label">This:</span>
<span class="price" id="old-price-326">
8,69 € </span>
</p>
<p class="special-price">
<span class="price-label">This is:</span>
<span class="price" id="product-price-326">
1,99 € </span> <span style="">/ 6.87 </span>
</p>
</div>
及
但是它不起作用。我不确定什么是
$preke
,但是如果它是一个支持正确类选择器的DOM选择器,您可以使用它
$preke->find('span[id^="product-price"]')
或
^=
告诉它查找ID以“product price”开头的元素,*=
告诉它查找ID包含“product price”的元素。我不确定$preke
是什么,但是如果它是一个支持正确类选择器的DOM选择器,那么您可以使用它
$preke->find('span[id^="product-price"]')
或
^=
告诉它查找ID以“product price”开头的元素,*=
告诉它查找ID包含“product price”的元素。为什么不使用类来获取它呢
echo $preke->find('.special-price', 0)->find('.price', 0)->plaintext;
这将使您获得1,99€
为什么不使用类
echo $preke->find('.special-price', 0)->find('.price', 0)->plaintext;
这将使您获得1,99€
,以下是您需要执行的操作:
foreach($preke->find('span[id^="product-price-"]') as $div) {} // note the ^ before the =
,以下是您需要做的事情:
foreach($preke->find('span[id^="product-price-"]') as $div) {} // note the ^ before the =
试着这样做可能会奏效
foreach($preke->find('span[id^="product-price-"]') as $div) { /* Code */ }
试着这样做可能有用
foreach($preke->find('span[id^="product-price-"]') as $div) { /* Code */ }
尝试$preke->find('span[id^=“product price-”])
。重复吗?它起作用了。感谢D4V1DTry$preke->find('span[id^=“product price-”])
。重复吗?它起作用了。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢。谢谢