SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Ippy
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cURL - tokenizing response

    I'm writing a php script to send off credit card information to my merchant gateway and receive the response.
    PHP Code:
        $ch curl_init();
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_POST1);
        
    curl_setopt($chCURLOPT_POSTFIELDS$fields);
        
    curl_setopt($chCURLOPT_URL$url);
        
    curl_setopt($chCURLOPT_SSL_VERIFYHOST1);
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
        
    $buffer curl_exec($ch);
        
    curl_close($ch); 
    the problem is that $buffer is just one long string in the form of subject::value subject::value. Eg. resptxt::approved rescode::0.

    for some reason though when i use explode(" ", $buffer) it doesn't seperate the string. It isn't even recognising the spaces as spaces.

    I even tried reading each char in as a test and echo'ing and it says char = " " but if (char == " ") returns false.

    I read something about curl encoding spaces or something but i'm not sure how i would go about decoding it.

    I tried using the curl_unescape but php says call to undefined function.

    I'm running
    CURL Information libcurl/7.11.2 OpenSSL/0.9.7d zlib/1.1.4
    with php version 4.3.8
    on apache 2.0.49 on windows

  2. #2
    SitePoint Addict silent's Avatar
    Join Date
    Jun 2004
    Location
    Roaming North America
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First thing I would try is
    PHP Code:
    $buffer curl_exec($ch);
    $buffer urldecode($buffer); 

  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Ippy
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah i did try that among other things... urldecode, rawurldecode.etc

    I did actually work out the problem i was using explode(" ", $buffer) in order to get seperate the values into an array. Turns out the reason it wasn't working is they weren't spaces at all, rather new lines (\n).

    The response was coming out as variable::value variable::value. whereas is was supposed to be
    Variable::value
    variable::value

    so as soon as i changed it to explode("\n", $buffer) it worked nicely.

    One of those stupid errors that costs you days hehe


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •