0

I'm forced to use cURL to submit a form to obtain the results I need, unfortunately I've been haunted by the tedious task of having to parse the results that are in JSON.

My end-goal is to get this into a table that is legible and not some big block of text.

array(1) { ["SE"]=> array(4) { ["errors"]=> array(0) { } ["removedname"]=> string

That is just the start of the results of the page. My code so far is:

$h = curl_init();
curl_setopt($h, CURLOPT_URL, "http://mywebsite.com/index.php");
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, array(
'user' => 'username',
'pass' => 'password',
'ph' => 'identifiyingInfo',
'vnum' => 'submit' # From the "Submit" button));
curl_setopt($h, CURLOPT_HEADER, false);
curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($h, CURLOPT_USERPWD, 'name:pass');
curl_setopt($h, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($h);

curl_close($h);

var_dump(json_decode($result, true));

After adding the <pre></pre> tags, this became a lot more clear to me, but I'm still just not sure how to access the items in this array.

array(1) {
["SE"]=>
array(4) {
    ["errors"]=>
    array(0) {
    }
    ["billwith"]=>
    string(10) "removedInteger"
    ["bill_detail"]=>
    array(1) {
        ["bill_item"]=>
        array(48) {
          [0]=>
          array(7) {
            ["type1identifier_id"]=>
            string(5) "removed coded string "
            ["prod"]=>
            string(15) "removed string"
            ["charge"]=>
            string(4) "1.36"
            ["misc_date"]=>
            string(6) "063014"
            ["misc_date2"]=>
            string(6) "000000"
            ["notes"]=>
            string(0) ""
            ["color"]=>
            string(4) "hide"
          }
          [1]=>
          array(7) {
          ["type1identifier_id""]=>
          string(5) "CP024"
          ["prod"]=>
          string(15) "removed string "
          ["charge"]=>
          string(3) ".00"
          ["misc_date"]=>
          string(6) "063014"
          ["misc_date2"]=>
          string(6) "000000"
          ["notes"]=>
          string(0) ""
          ["color"]=>
          string(4) "hide"
double-beep
  • 5,031
  • 17
  • 33
  • 41
aaron1312
  • 37
  • 11
  • 2
    you have already decoded the response, its an array now, just treat it as such – Kevin Nov 03 '14 at 08:42
  • Indeed, if you use $result = json_decode($result); PHP will turn the json into an stdClass object. You can use it like $result->param after that. – Peter Nov 03 '14 at 08:54
  • Maybe I'm getting ahead of myself, are the results a two dimensional array and I'm just not seeing the values? – aaron1312 Nov 03 '14 at 08:57
  • That's possible. If you use the html
     and 
    before and after your var_dump it will make the contents a bit clearer.
    – Peter Nov 03 '14 at 08:59
  • 1
    the response is not accurate. post the replied json data – Njuguna Mureithi Nov 03 '14 at 09:01
  • I provided additional information once I got the
     tags in.  I'm jut not sure how to go about accessing these pieces of the array.
    – aaron1312 Nov 03 '14 at 22:20
  • If I could at least figure out what I'm doing wrong to try and print "removedInteger" from the "billwith" I'm positive I can figure this out. – aaron1312 Nov 04 '14 at 01:38
  • Bump...? I haven't had any luck in any way of obtaining the sub-value of these keys. :( – aaron1312 Nov 08 '14 at 23:27

0 Answers0