bondigor69 Posted June 16, 2012 Share Posted June 16, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/264299-scrape-price-php-really-easy-but-i-cant-lol/ Share on other sites More sharing options...
zPlus Posted June 26, 2012 Share Posted June 26, 2012 If it's a standard format you can try substr(..), otherwise regular expressions but these functions take up more resources. By the way I don't see the problem you have echoing that variable... Quote Link to comment https://forums.phpfreaks.com/topic/264299-scrape-price-php-really-easy-but-i-cant-lol/#findComment-1357132 Share on other sites More sharing options...
dc2007 Posted June 27, 2012 Share Posted June 27, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/264299-scrape-price-php-really-easy-but-i-cant-lol/#findComment-1357349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.