简体   繁体   English

从元素 html dom 解析器中删除 span 标签

[英]Remove span tag from element html dom parser

I have code like this, and it's fetching data from other website.我有这样的代码,它从其他网站获取数据。

require('simple_html_dom.php');

$html = file_get_html("www.example.com");
    
$info['diesel']   = $html->find(".on .price",0)->innertext;
$info['pb95']   = $html->find(".pb .price",0)->innertext;
$info['lpg']   = $html->find(".lpg .price",0)->innertext;

The html code from other website looks:其他网站的 html 代码如下:

<a href="#" class="station-detail-wrapper on text-center active">
   <h3 class="fuel-header">ON</h3>
   <div class="price">
      5,97
      <span>zł</span>
   </div>
</a>

So if i use echo $info['diesel'] it shows me 5,97 zł .所以如果我使用echo $info['diesel']它会显示我5,97 zł I would like to delete this <span>zł</span> to show price only.我想删除此<span>zł</span>以仅显示价格。

也许你可以用空白替换那个 span 标签:

echo $info['diesel']=str_replace("<span>zł</span>","",$info['diesel']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM