1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help at parse in PHP

Discussion in 'PHP & Perl' started by Grexslo, Oct 15, 2013.

Tags:
  1. Grexslo

    Grexslo Newbie

    Joined:
    Oct 20, 2011
    Messages:
    34
    Likes Received:
    0
    Hello,
    I am neew in PHP but try resolve my problem but I don"t know how to.
    Is here someone who can help me parse price in below link:

    Code:
    [COLOR=#000000][FONT=courier new]<?php[/FONT][/COLOR]
    [COLOR=#000000][FONT=courier new]preg_match_all("/Price<\/td><td class\=\"price\">([0-9\.]*?)<\/td/si",file_get_contents('[/FONT][/COLOR]informers.mt5.com/en/quotes_online/informer/sz=540_20&ticker=NZDCHF[COLOR=#000000][FONT=courier new]'), $result);[/FONT][/COLOR]
    [COLOR=#000000][FONT=courier new]echo "Price: ";[/FONT][/COLOR]
    [COLOR=#000000][FONT=courier new]echo $result[1][0];[/FONT][/COLOR]
    [COLOR=#000000][FONT=courier new]?>
    [/FONT][/COLOR]
    Thanks for all help!
     
  2. apoorv

    apoorv Regular Member

    Joined:
    Aug 31, 2011
    Messages:
    301
    Likes Received:
    62
    I don't see price on the page you're trying to parse at all. Are you sure it's the correct URL?

    Also, you need to add http at the start of the URL. You may also want to use PHPQuery—that might make your job slightly easier.

    Also, this seems to work (it's not the price, of course, but the td class is the only thing you would need to change I think):

    PHP:
    <?php
      preg_match_all
    ("/<td class=\"lines\">([0-9\.]*?)<\/td>/si"file_get_contents('http://informers.mt5.com/en/quotes_online/informer/sz=540_20&ticker=NZDCHF'), $result);
      echo 
    "Price: ";
      echo 
    $result[1][0];
      
    var_dump($result);
    ?>
    I've added var_dump at the end... you should remove it, though it just for testing.
     
    Last edited: Oct 15, 2013
  3. Grexslo

    Grexslo Newbie

    Joined:
    Oct 20, 2011
    Messages:
    34
    Likes Received:
    0
    Yes, is correct URL. I know that I must put http on link, but I can"t send post with this :)
     
  4. apoorv

    apoorv Regular Member

    Joined:
    Aug 31, 2011
    Messages:
    301
    Likes Received:
    62
    Ah, I just made an edit to the previous post. I still don't see the price, but testing it out on another td works just fine.
     
  5. DarkPixel

    DarkPixel Jr. VIP Jr. VIP Premium Member

    Joined:
    Oct 4, 2011
    Messages:
    1,328
    Likes Received:
    1,239
    Location:
    ↓↓↓↓
    Home Page:
    You need regex help, not PHP help.Loading that link, I can't find "price" in the source code of the website, so your regex is wrong.

    EDIT: didn't see your edit :)
     
  6. Grexslo

    Grexslo Newbie

    Joined:
    Oct 20, 2011
    Messages:
    34
    Likes Received:
    0
    Thanks,
    I will use google, but I don"t know what I must :/
     
  7. ebraheeemz

    ebraheeemz Registered Member

    Joined:
    Oct 13, 2013
    Messages:
    58
    Likes Received:
    2
    Location:
    Jordan
    hello
    if you looking for good and very easy parsing technique, you can do search about [h=1]Simple HTML DOM Library[/h]
     
  8. cz1349

    cz1349 Newbie

    Joined:
    Oct 31, 2013
    Messages:
    11
    Likes Received:
    2
    I checked page and I think that for you will be better to parse JSON which is returned:

    /quotes_online/ajax/tickers=nzdchf&tz=0&callback=update_quotes

    Code:
    update_quotes({"status":true,"quotes":{"NZDCHF":{"symbol":"NZDCHF","lasttime":1383260752,"digits":4,"change":"0.0001","bid":"0.7490","ask":"0.7500"}},"time":"20:05"});