![](/img/trans.png)
[英]Strip HTML tags from within the title and alt attributes of an image tag
[英]Strip attributes in HTML tag span
我正在通過CURL請求獲取數據,並且在解析HTML時,有些跨度的屬性沒有被整齊地解析。
HTML代碼段
<div class="ftlt" style="width:250px;">
<div class="tdiv"><span class="prop_price_img"></span><span class="property_price">PROPERTY_PRICE</span></div>
<p class="adPrice">AREA</p>
<h4>
<p style="float:left;width:251px;font-family:Arial, Helvetica, sans-serif;font-size:13px;padding:2px 10px 10px 0px;"><a href="some link" title="title">TITLE</a>,
<span style="color:#666;"> CITY_NAME.</span>
<a title="title, Sale" style="color:#3266CC;font-size:12px;text-decoration:underline;">View on map</a></p>
</h4>
<p style="font-weight:bold;color:#666;">
Premium
</p>
<div class="clr"></div>
</div>
我必須整潔地訪問CITY_NAME元素。 我已經能夠通過HTML DOM將該節點獲取為
$spans = $html->find(div.ftlt span);
$city_value=strip_tags($spans[2]);
這個$city_value
變$city_value
。 我嘗試了removeAttribute方法。也許我做的不正確。
如果可以使用正則表達式,我想知道如何?
$spans = $html->find(div.ftlt span);
$city_value=$spans[2]->nodeValue;
為什么不使用nodeValue ?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.