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

Link to comment
Share on other sites

  • 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;

}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.