Jump to content

Scrape price PHP ( really easy ) but I can't lol


bondigor69

Recommended Posts

hey guys im using wordpress and In every post that I have there is a price

<strong>Online Price</strong>:$ 20.00<br>
<span style="color: red;">Your Price</span>:$ 17.91<br>

I want to get the second price (17.91) without dollar sign and space and ECHO it somewhere else.

Can someone help me please

PS every post have the same HTML above only price changing

  • 2 weeks later...

try

 

insert the content example

 

$content = get_url("http://url-to-content");

 

preg_match("~<span style="color: red;">Your Price</span>:$(.+?)<br>~s", $content, $match);   

        $price = preg_replace("$","",$match[1]);

        $price = ltrim(rtrim($price));

       

        echo $price;

 

 

function get_page($url){

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_URL, $url);

    $content = curl_exec($ch);

    return $content;

}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.