1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Echo parsed string

Discussion in 'PHP' started by bondigor69, Jun 16, 2012.

  1. #1
    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
    SEMrush
     
    bondigor69, Jun 16, 2012 IP
    SEMrush
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    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.
     
    Rukbat, Jun 16, 2012 IP
  3. webshore88

    webshore88 Active Member

    Messages:
    130
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #3
    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.
     
    webshore88, Jun 16, 2012 IP
  4. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #4
    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
     
    bondigor69, Jun 17, 2012 IP
  5. davidson_11

    davidson_11 Active Member

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    80
    #5
    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.
     
    davidson_11, Jun 17, 2012 IP
  6. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #6
    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
     
    bondigor69, Jun 17, 2012 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    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.
     
    Rukbat, Jun 17, 2012 IP
  8. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #8
    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??
     
    bondigor69, Jun 17, 2012 IP
  9. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #9
    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).
     
    Rukbat, Jun 17, 2012 IP
  10. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #10
    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)
     
    bondigor69, Jun 17, 2012 IP
  11. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #11
    No one can give you the code without having it, and we don't have it.
     
    Rukbat, Jun 17, 2012 IP
  12. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #12
    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 ....
     
    bondigor69, Jun 17, 2012 IP
  13. NetStar

    NetStar Notable Member

    Messages:
    2,388
    Likes Received:
    507
    Best Answers:
    21
    Trophy Points:
    245
    #13
    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.
     
    NetStar, Jun 17, 2012 IP
  14. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #14
    YEs it works but it always shows the price 17.91
    The prices are changing on every page
     
    bondigor69, Jun 17, 2012 IP
  15. NetStar

    NetStar Notable Member

    Messages:
    2,388
    Likes Received:
    507
    Best Answers:
    21
    Trophy Points:
    245
    #15
    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
     
    NetStar, Jun 17, 2012 IP
  16. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #16
    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.
     
    bondigor69, Jun 17, 2012 IP
  17. NetStar

    NetStar Notable Member

    Messages:
    2,388
    Likes Received:
    507
    Best Answers:
    21
    Trophy Points:
    245
    #17
    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.
     
    NetStar, Jun 17, 2012 IP
  18. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #18
    I have access to the HTML. what I have to do now
    Help will be appreciated
    Thank you
     
    bondigor69, Jun 17, 2012 IP
  19. NetStar

    NetStar Notable Member

    Messages:
    2,388
    Likes Received:
    507
    Best Answers:
    21
    Trophy Points:
    245
    #19
    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.
     
    NetStar, Jun 17, 2012 IP
  20. NetStar

    NetStar Notable Member

    Messages:
    2,388
    Likes Received:
    507
    Best Answers:
    21
    Trophy Points:
    245
    #20
    Paste the code here...
     
    NetStar, Jun 17, 2012 IP