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. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #21
    <strong>Online Price</strong>:$ 20.00<br>
    <span style="color: red;">Your Price</span>:$ 17.91<br>
    Check <a href="/go/" target="_blank">Puma Tshirt</a> to get your deal!</p>
    HTML:
    this is the html code
    Is that what you looking for
     
    bondigor69, Jun 17, 2012 IP
  2. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #22
    I understand what you want.
    But the price is already generated into my wordpress post.
    A plugin called WProbot is generating those prices.
    So each post/article has his own price already in the html
     
    bondigor69, Jun 17, 2012 IP
  3. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #23
    Oh.. so you aren't creating a PHP script...
     
    NetStar, Jun 17, 2012 IP
  4. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #24
    I want to creat a small snippet of php to get that price
    Then I'll paste this php inside my html link. I'll show you an example. This is my sharing link on pinterest.
    This is my link
    <a href="http://pinterest.com/pin/create/button?url=<?php echo get_permalink() ?>&media=<?php $image_id = get_post_thumbnail_id();
    $image_url = wp_get_attachment_image_src($image_id,'large', true);
    echo $image_url[0];  ?>&description=<?php the_title(); ?> via @cheetahreviews <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        echo '%23' . $tag->name . ' '; 
      }
    }
    ?>">  Pin It</a>
    PHP:
    But when a visitor comes to my page the link is already generated and looks like that
    http://pinterest.com/pin/create/button?url=http://hytyeview.org/puma-logo-tee-young/&media=http://huyhyview.org/wp-content/uploads/2012/05/puma-tshirt-small.jpg&description=Puma%20logo%20tee%20for%20young%20via%20@chhyhiews%20%23addidas%20%23nike%20%23puma%20%23shoes%20%23tshirt
    HTML:
    When they click the Pinterest share all my page info are going to show on pinterest
    BUT IM ONLY MISSING THE PRICE.
     
    bondigor69, Jun 17, 2012 IP
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #25
    Let me see if I follow this. You creating a SEPARATE php script which you wish to display the price that is listed on a different page?

    So basically you would have to fetch the HTML content... then extract the price to have access to it, right?
     
    NetStar, Jun 17, 2012 IP
  6. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #26
    YEESS YOU GOT IT
    but the price is liste on the same page
     
    bondigor69, Jun 17, 2012 IP
  7. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #27
    The price is listed on the same page? This is where you lose me.
     
    NetStar, Jun 17, 2012 IP
  8. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #28
    its hard to explain because of my english but I'll try
    I put those php "snippets" in my wordpress template.
    Everytime the page is loading those codes/snippets are loaded in those pages.
    So every code/snippet is on those pages.
    So if I get the PHP code to parse the price between the 2 strings below and paste it in my template, the php code will parse the price on each dynamicly.
    like this PHP for example
    <?php echo get_permalink() ?>
    PHP:
    is loaded on every page but getting the permalink for the page that is loading
     
    bondigor69, Jun 17, 2012 IP
  9. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #29
    Is get_permalink() defined by your WordPress Plugin? Or is that your code? If it's defined by your PlugIn and your PlugIn defines the Price you should be able to use the Variable for the price and not have to worry about extracting.
     
    NetStar, Jun 17, 2012 IP
  10. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #30
    get permalink is defyned by Wordpress. The price is the plugin that defines it. but I cant find it.
    It will be easier to extract the price because the plugin generating an wordpress shortcode and this shortcode is generating the price.
    Also each shortcode is different because the price comes from amazon and the shortcode contains the ASIN(product number).
    So the shortcode are not unique
     
    bondigor69, Jun 17, 2012 IP
  11. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #31
    Without seeing the PHP source I couldn't tell you how to access the Price. The only way I can suggest is to Launch a request to download the HTML page. Then extract the price.

    It's hardly the proficient way to do this...but It will work.

    
    <?php
    $url = "http://some-url/to/the/page/with-the-price.html";
    
    //
    // Fetch web page
    //
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $myHtmlPrice = curl_exec($ch);
    curl_close($ch);
    
    //
    // Extract Price
    //
    $matches = array();
    preg_match('/<span style="color: red;">Your Price<\/span>:\$ (.*)<br>/', $myHtmlPrice, $matches);
    $myPrice = $matches[1];
    
    //
    // Outout
    //
    print "The price is: $myPrice";
    
    ?>
    
    PHP:
     
    NetStar, Jun 17, 2012 IP
  12. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #32
    no even that dosent work
    I can't send you the plugin because it exeed the upload limit.
    So I guess I'll do it without the price.
    Thank you very much
     
    bondigor69, Jun 17, 2012 IP
  13. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #33
    The code does work based on the html snippet you gave me.
     
    NetStar, Jun 17, 2012 IP
  14. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #34
    I FINALLY FOUND HOW TO DO IT.

    OOOOOHHHH MY GOD it was so stupid and easy.(It was 3 days I was looking for a solution)

    I went in my template and added this

    <?php
    $postprice = '{price}';
    ?>
    PHP:
    the {price} tag is generating the tag for each post.

    Then I went in my general template and added to the pinterest link
    <?php
    echo $postprice;
    ?>
    PHP:
    So now it shows me the price on I want on each post and in the share link.

    The only problem is the {price} is generated by php also.
    So when it generates the post I get a blan page because its adding a space(I dont know why)
    like that
    <?php
    $ postprice = '$ 17.91';
    ?>
    PHP:
    Do you have an idea why???
     
    bondigor69, Jun 17, 2012 IP
  15. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #35
    You want to get rid of the space inbetween $ and 17.91?

    If so use this:

    
    $postprice = "{price}";
    $postprice = str_replace(" ", "", $postprice);
    
    
    PHP:
    Or are you talking about the space between $ and postprice?
     
    NetStar, Jun 17, 2012 IP
  16. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #36
    the space between $ and postprice
     
    bondigor69, Jun 17, 2012 IP
  17. bondigor69

    bondigor69 Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #37
    @NetStar r u there???:confused:
     
    bondigor69, Jun 17, 2012 IP
  18. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #38
    I'm not looking at your code which makes this terribly difficult. Nor do I know what you are using. If there is a space in your variable the solution is to simply delete the space that you added. If you are suggesting that a PHP script is outputting your PHP code and is placing the space there.. double check your template and make sure you have the code wrapped in the <?php ?> tags.
     
    NetStar, Jun 18, 2012 IP
  19. webshore88

    webshore88 Well-Known Member

    Messages:
    130
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #39
    I think buddy your programming knowledge is very basic, you should contact a pro to fix your problem.
     
    webshore88, Jun 18, 2012 IP