Search code examples
phpsimple-html-dom

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:

<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ł. I would like to delete this <span>zł</span> to show price only.


Solution

  • May be you can replace that span tag with blank:

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