PHP
php json encode
$person = array(
"name" => "Johny Carson",
"title" => "CTO"
);
$personJSON=json_encode($person);//returns JSON string
php array json encode key and value
json_encode($thearray, JSON_FORCE_OBJECT)
How to JSON encode a PHP array
<?php
// the php array
$array = array();
$array['key1'] = "value1";
$array['key2'] = "value2";
$array['key3'] = "value3";
// encode the php array into JSON format
$json = json_encode($array);
// check out the results
var_dump($json);
?>
jsondecode php array
<?php
$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
$data = json_decode($json);
if (count($data->stand)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($data->stand as $idx => $stand) {
// Output a row
echo "<tr>";
echo "<td>$stand->afko</td>";
echo "<td>$stand->positie</td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
?>
javascript function in php json_encode
$function = "#!!function(){}!!#";
$message = "Hello";
$json = array(
'message' => $message,
'func' => $function
);
$string = json_encode($json);
$string = str_replace('"#!!','',$string);
$string = str_replace('!!#"','',$string);
echo $string;
jsondecode php array
<?php
$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
$data = json_decode($json);
if (count($data->stand)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($data->stand as $idx => $stand) {
// Output a row
echo "<tr>";
echo "<td>$stand->afko</td>";
echo "<td>$stand->positie</td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
?>
jsondecode php array
<?php
$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
$data = json_decode($json);
if (count($data->stand)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($data->stand as $idx => $stand) {
// Output a row
echo "<tr>";
echo "<td>$stand->afko</td>";
echo "<td>$stand->positie</td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
?>
jsondecode php array
<?php
$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
$data = json_decode($json);
if (count($data->stand)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($data->stand as $idx => $stand) {
// Output a row
echo "<tr>";
echo "<td>$stand->afko</td>";
echo "<td>$stand->positie</td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
?>
json encode php
<?php
echo json_encode(array("statusCode"=>201,"system"=>1));
?>
php json_encode indent
$pretty=json_encode($foo, JSON_PRETTY_PRINT);
json_encode php
$person = array(
"name" => "Johny Carson",
"title" => "CTO"
);
$personJSON=json_encode($person);//returns JSON string
=====================================================
$function = "#!!function(){}!!#";
$message = "Hello";
$json = array(
'message' => $message,
'func' => $function
);
$string = json_encode($json);
$string = str_replace('"#!!','',$string);
$string = str_replace('!!#"','',$string);
echo $string;
json_encode()
json_encode(['name' => 'Jake', 'country' => 'Philippines'])
jsondecode php array
<?php
$json=file_get_contents("http://west.basketball.nl/db/json/stand.pl?szn_Naam=2014-2015&cmp_ID=373");
$data = json_decode($json);
if (count($data->stand)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($data->stand as $idx => $stand) {
// Output a row
echo "<tr>";
echo "<td>$stand->afko</td>";
echo "<td>$stand->positie</td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
?>
PHP - json_encode()
<?php
$age = array("Peter"=>35, "Ben"=>37, "Joe"=>43);
echo json_encode($age);
?>