I am trying to scrape some data by using curl and simple_html_dom library, i can successfully scrape data but the problem is i don't want some text with data.
This is the code i am using :
$price = $html->find("div[id='vi-mskumap-none'] span[itemprop='price']",0)->plaintext;
This is html source code :
<div id="vi-mskumap-none" style="" class="u-flL w29 vi-price ">
<span class="notranslate" id="prcIsum" itemprop="price" style="" content="515.0">US $515.00</span>
It is scraping
US $515.00
But I want to remove US $ and only want
515.00
can someone please help
Since you say that the format of the string will always be the same, there's no need for any regex. Just use str_replace()
$price = 'US $515.00';
$price = str_replace('US $', '', $price);
Here's a demo: https://3v4l.org/ZDl5t
That will give you a string: 515.00
. If you want it to be a real float, then just cast it:
$price = (float)str_replace('US $', '', $price);