'); // Command is tabrestore $request->addChild('command', 'tabrestore'); // Setup authentication $usernode=$request->addChild('becomeuser'); $usernode->addChild('username', $_SESSION["username"]); $usernode->addChild('password', getpassword()); // Go through each table row $first = 0; foreach($cont as $line){ if($first == 0){ // The 1st line is the table header // It does not need special processing // Create string containing all array elements $str = implode(",", $line); $request->addChild('data', $str); $first = 1; continue; } // Go through each column foreach($line as &$col){ // If the column does begins and end with a quote // Change quotes to " if(!empty($col) && !preg_match('/^".*"$/', $col)) { $col = '"' . $col . '"'; } } // Sort line ksort($line, SORT_NUMERIC); $keys = array_keys($line); $max = count($line) - 1; if($keys[$max] != $max){ for ($i = 0; $i <= $keys[$max]; $i++) { if (!isset($line[$i])) {$line[$i]='';} } ksort($line, SORT_NUMERIC); } // Create string containing all array elements $str = implode(",", $line); // Replace " with " $str = str_replace('"', '"', $str); // Replace ' with ' $str = str_replace("'", ''', $str); $request->addChild('data', $str); } // Run command $request->addChild('table', $tab); $xml = submit_request($request, 0); // Reply in the form of JSON $rtn = array("rsp" => $xml); echo json_encode($rtn); ?>