Beispiel #1
0
    if (is_array($arr)) {
        foreach ($arr as $key => $val) {
            if (is_array($val)) {
                $retStr .= '<li>' . $key . ' => ' . pp($val) . '</li>';
            } else {
                $retStr .= '<li>' . $key . ' => ' . $val . '</li>';
            }
        }
    }
    $retStr .= '</ul>';
    return $retStr;
}
//next example will recieve all messages for specific conversation
$service_url = 'https://api.guildwars2.com/v2/characters/Lotlei?access_token=80221103-2703-1A46-A3AA-8D4674BBD1B11BEDA9A1-E515-44DB-87F3-FD177FB190C9';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
    $info = curl_getinfo($curl);
    curl_close($curl);
    die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
    die('error occured: ' . $decoded->response->errormessage);
}
echo 'response ok!<br>';
//echo _format_json($decoded);
echo _format_json($curl_response);
//echo $curl_response;
// Loop objects
$sql = "SELECT * FROM ha_data ORDER BY DataId";
if ($result = $mysqli->query($sql)) {
    while ($row = $result->fetch_assoc()) {
        ?>
								<tr>
									<td><?php 
        echo $row["DataId"];
        ?>
</td>
									<td><?php 
        echo $row["DataName"];
        ?>
</td>
									<td><?php 
        echo _format_json($row["DataText"], true);
        ?>
</td>
									<td><?php 
        echo $row["DataLastUpdated"];
        ?>
</td>
								</tr>
						<?php 
    }
}
?>
					</table>
				</div>
			</div>
		</div>
<?php

$json = array('results' => array('address_components' => array(array("long_name" => "Dhaka", "short_name" => "Dhaka", "types" => array("locality", "political")), array("long_name" => "Dhaka", "short_name" => "Dhaka", "types" => array("administrative_area_level_2", "political")), array("long_name" => "Dhaka Division", "short_name" => "Dhaka Division", "types" => array("administrative_area_level_1", "political")), array("long_name" => "Bangladesh", "short_name" => "BD", "types" => array("country", "political")))), 'status' => 'OK');
header("HTTP/1.1 200 OK");
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: http://www.example.com/');
header('Access-Control-Max-Age: 3628800');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
$new_json = json_encode($json);
echo _format_json($new_json);
echo "\r\n \r\n";
//foreach (getallheaders() as $name => $value) {
//    echo "$name: $value\n";
//}
//print_r(getallheaders());
function _format_json($json, $html = false)
{
    $tabcount = 0;
    $result = '';
    $inquote = false;
    $ignorenext = false;
    if ($html) {
        $tab = "&nbsp;&nbsp;&nbsp;";
        $newline = "<br/>";
    } else {
        $tab = "\t";
        $newline = "\n";
    }
    for ($i = 0; $i < strlen($json); $i++) {
        $char = $json[$i];
        if ($ignorenext) {