cURL output related question.

Discussion in 'PHP' started by afridy, Oct 5, 2009.

  1. #1
    hi,
    i am trying to take the page source from a 3rd party site.
    it works fine. but the page source is printed in my page from which i am calling below code.

    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://somesite.com/test.htm");
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch); //execute the funcion now with above settings.
    curl_close($ch);
    
    //manipulating the out put of curl 
    $start=strpos($data,"<strong class=\"downloads\">");
    $start2=strpos($data,"</strong>",($start + 26));
    //grabbing a piece of string
    echo rtrim(ltrim(substr($data,$start,$start2)));
    ?>
    Code (markup):
    now i need to stop the printing of the source of the destination in my page.
    i just tried making curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    then the latter string manipulation part returns nothing.

    :confused:
     
    afridy, Oct 5, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    returntransfer needs to be true as it was in your original script. My guess is your substr thingamagic isn't working and it's simply displaying everything. Remove the last echo (add //) then refresh and see if it's still outputting.

    If it's not, then your substr is at fault and can't find the piece of string you are trying to find. You should account for this by checking if strpos === false.
     
    premiumscripts, Oct 5, 2009 IP
    afridy likes this.
  3. afridy

    afridy Well-Known Member

    Messages:
    810
    Likes Received:
    116
    Best Answers:
    0
    Trophy Points:
    135
    #3
    thank you primum
    let me try your suggession :)
     
    afridy, Oct 5, 2009 IP
  4. afridy

    afridy Well-Known Member

    Messages:
    810
    Likes Received:
    116
    Best Answers:
    0
    Trophy Points:
    135
    #4
    problem [solved]

    yes, problem in substr only :)
    tx men premiumscripts :)
     
    afridy, Oct 5, 2009 IP