hello guys Please help me with that I have this on every page <span style="color: red;">Your Price</span>:$ 17.91<br> HTML: I want to get the second price (17.91) without dollar sign and space and ECHO it somewhere else with PHP Can someone help me please The price is always changing so I think I need a regular expression or wtv I want to echo the price after also thank you
Where is the price coming from? A database? Hard-coded in the page? The one thing you don't want to do is scrape your own page (which you'd be doing with a RegEx). Something is writing the text to the page - the best way to get it is at that point.
if your price is in a variable then use <?=$price?> where ever you want to echo price. And one more thing your file extension must be .php, unless echo will not work.
The prices is generated by a wordpress plugin called wprobot (amazon module) But Im not a pro in PHP. I d'ont know how to echo the price
Best bet is to find the PHP variable used to display the price from the wordpress plugin, and echo it elsewhere within the page. If you can't locate the variable or find the plugin difficult to understand, contact the author of the plugin.
there is the price variables $asin = $item->ASIN; $acontent = wpr_random_tags($acontent); $acontent = str_replace("{title}", $item->ItemAttributes->Title, $acontent); $acontent = str_replace("{description}", $desc, $acontent); $acontent = str_replace("{features}", $features, $acontent); $acontent = str_replace("{thumbnail}", $thumbnail, $acontent); $acontent = str_replace("{smallimage}", $item->SmallImage->URL, $acontent); $acontent = str_replace("{mediumimage}", $item->MediumImage->URL, $acontent); $acontent = str_replace("{largeimage}", $item->LargeImage->URL, $acontent); $acontent = str_replace("{buynow}", '<a href="'.$item->DetailPageURL.'" rel="nofollow"><img src="'.$imagepath.'buynow-small.gif" /></a>', $acontent); $acontent = str_replace("{buynow-big}", '<a href="'.$item->DetailPageURL.'" rel="nofollow"><img src="'.$imagepath.'buynow-big.gif" /></a>', $acontent); $acontent = str_replace("{buynow-ger}", '<a href="'.$item->DetailPageURL.'" rel="nofollow"><img src="'.$imagepath.'buynow-ger.gif" /></a>', $acontent); $acontent = str_replace("{price}", $price, $acontent); $acontent = str_replace("{listprice}", $listprice, $acontent); $savings = str_replace("$ ", "", $listprice) - str_replace("$ ", "", $price); $acontent = str_replace("{savings}", $savings, $acontent); $acontent = str_replace("{url}", $item->DetailPageURL, $acontent); $acontent = str_replace("{avgrating}", $item->CustomerReviews->AverageRating, $acontent); $acontent = str_replace("{reviewsnum}", $item->CustomerReviews->TotalReviews, $acontent); $noqkeyword = str_replace('"', '', $keywords); $acontent = str_replace("{keyword}", $noqkeyword, $acontent); $acontent = str_replace("{Keyword}", ucwords($noqkeyword), $acontent); $acontent = str_replace("{link}", $link, $acontent); $acontent = str_replace("{asin}", $asin, $acontent); $acontent = str_replace("{price-updating}", $price, $acontent); PHP: I dont think it will work because the price,produc name etc are not generated on page. I think it will be less complicated it I parse the page with regex and echo the price
I wouldn't count on short tags being enabled. If you can't read PHP, you can't debug it. You'll have to get someone to do it for you.
it not easier to just parse the content with regex and find the price between <span style="color: red;">Your Price</span>:$ Code (markup): and <br> Code (markup): and after just echo it??
You could create a race condition doing that. Then your page will never display (at best - at worst it could crash the user's browser).
well.... how can i find anything between <span style="color: red;">Your Price</span>:$ HTML: and <br> HTML: and echo this I'll give 5$ to anyone that give me the PHP code (if it works)
I have that script that works <?php function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } $fullstring = '<span style="color: red;">Your Price</span>:$ 17.91<br>'; $parsed = get_string_between($fullstring, "Your Price</span>:$ ", "<br>"); echo $parsed; //17.91 ?> PHP: But the problem is the price is always changing so how can I do it with regex or ....
Personally I believe this is cheap...but it will help you. Assuming $myHtmlPrice has the value of the HTML code you posted: <?php $myHtmlPrice = '<span style="color: red;">Your Price</span>:$ 17.91<br>'; $matches = array(); preg_match('/<span style="color: red;">Your Price<\/span>:\$ (.*)<br>/', $myHtmlPrice, $matches); $myPrice = $matches[1]; print "The price is: $myPrice"; ?> PHP: This will print: The price is: 17.91.
So? If you have access to the html the snipet above will pull the price no matter what the price is. Change the price in $myHtmlPrice and you'll see
yes I understand that. But I want to find the price automaticly. I have more than 200 pages ->> 200 prices. Each page has a different price.
What I showed you is an example of scraping the price from the HTML code. The regular expression will work on each one of those pages regardless of the change in price. In other words, you will be able to scrape the price without obviously knowing the price all you need is access to the html.
I'll make it easier for you to understand. Everything underlined is static and never changes. <span style="color: red;">Your Price</span>:$ 17.91<br> The only item that changes is the price.. which is dynamic and pulled with each page. The (.*) in the regular expression fetches the dynamic content with in the static code. preg_match('/<span style="color: red;">Your Price<\/span>:\$ (.*)<br>/', $myHtmlPrice, $matches); As long as you have access to the HTML code...you can pull the price on every page with the example I gave you.