Read a URL through cURL

Discussion in 'PHP' started by temp2, Oct 1, 2007.

Thread Status:
Not open for further replies.
  1. #1
    I read PHP Man about cURL, but don't see section mention to get data from a URL into a string variable. Can everybody show me the this code?

    Thank you very much
     
    temp2, Oct 1, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $ch = curl_init('http://example.com');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $content = curl_exec($ch);
    curl_close($ch);
    
    PHP:
     
    nico_swd, Oct 2, 2007 IP
  3. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #3
    @nico_swd: thank you very much, this code work good. Does is CURLOPT_RETURNTRANSFER determining factor? In PHP Man, I can't find section explain about these options, can you show me?
     
    temp2, Oct 2, 2007 IP
  4. ds316

    ds316 Peon

    Messages:
    154
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    http://php.net/curl_setopt

    That manual topic describes all the options for curl, and yes in nico_swd's example CURLOPT_RETURNTRANSFER is the determining factor.

    I hope I've been of some help to you.
     
    ds316, Oct 2, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    EDIT: Beat me to it.

    Without setting the returntransfer to true, curl_exec() will output the result, and you're not able to store it in a variable.
     
    nico_swd, Oct 2, 2007 IP
Thread Status:
Not open for further replies.