0

When the CURL response is returned in format like below.

Array
(
    [timestamp] => 20150409065254
    [callback_status_code] => 200
    [fingerprint] => 252839e4790446a4bdd3a353aa232281a7a0b464
    [txnid] => 219773
    [merchant] => ABC0001
    [restext] => Approved
    [rescode] => 00
    [expirydate] => 052016
    [settdate] => 20150409
    [refid] => t1
    [pan] => 444433...111
    [summarycode] => 1
    )

is there any way to access its data as array. Its just in array format not array

I'm using following code.

$options = array(
        CURLOPT_RETURNTRANSFER => true,   // return web page

    );

$param = http_build_query($data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$content  = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);
echo $content;

Any help guys ???

4
  • 1
    Get whoever is supplying the array to use json_encode(). Then, when you get the data, use json_decode($response, true); Commented Apr 9, 2015 at 7:43
  • 3
    No. That output looks like the result of print_r(). It's designed to be human-readable, but it's not possible to parse it reliably. Commented Apr 9, 2015 at 7:43
  • @hd its from third party I can't access to that. Commented Apr 9, 2015 at 7:44
  • @JobinJose then contact them as that seems more like a debug message (human readable array print_r) than a usable response. Commented Apr 9, 2015 at 7:45

1 Answer 1

1

You can try the print_r_reverse() function described here: http://php.net/manual/en/function.print-r.php#93529

So then you would define this function somewhere, and change the last couple lines of your code as follows:

...
$content = curl_exec($ch);
$myArray = print_r_reverse($content);
$status = curl_getinfo($ch);
curl_close($ch);
// Do something with $myArray

Hope that helps.

Sign up to request clarification or add additional context in comments.

7 Comments

Did you follow the instructions in that link I sent you? Did you create that function? What exactly is happening when you try execute that code?
I copied that function then tried this $ar = (print_r_reverse($content)); echo $ar['pan']; but its empty
instead of runing echo $ar['pan']; Try running var_dump($ar); and take a look to see what is outputted. See if it is what you expect.
it work but that not necessary to use print_r_reverse even print_r() do the same it just out put the sting not in array format!!.
I've just tested, and it works perfectly. Look at the code here: pastebin.com/taeK8iT8
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.