5
foreach ($results as $url => $entity) {
8
$json .= '"type":"'.$type.'",';
11
foreach ($entity as $key => $value) {
13
$json .= '"'.$key.'":' . (is_object($value) ? json_encode($value->getRawValue()) : json_encode($value));
14
$json .= ($nb1 == $j ? '' : ',');
17
$json .= ($nb == $i ? '' : ',');
23
* Indents a flat JSON string to make it more human-readable
24
* @author http://recursive-design.com/blog/2008/03/11/format-json-with-php/
25
* @param string $json The original JSON string to process
26
* @return string Indented version of the original JSON string
28
function indent($json) {
32
$strLen = strlen($json);
38
for($i = 0; $i <= $strLen; $i++) {
40
// Grab the next character in the string
41
$char = substr($json, $i, 1);
43
// Are we inside a quoted string?
44
if($char == '"' && $prevChar != '\\') {
45
$outOfQuotes = !$outOfQuotes;
47
// If this character is the end of an element,
48
// output a new line and indent the next line
49
else if(($char == '}' || $char == ']') && $outOfQuotes) {
52
for ($j=0; $j<$pos; $j++) {
53
$result .= $indentStr;
56
// Add the character to the result string
59
// If the last character was the beginning of an element,
60
// output a new line and indent the next line
61
if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
63
if ($char == '{' || $char == '[') {
66
for ($j = 0; $j < $pos; $j++) {
67
$result .= $indentStr;
b'\\ No newline at end of file'
2
<?php $nb = count($results); $i = 0 ; foreach ($results as $url => $entity): ++$i ?>
4
"type": "<?php echo $type ?>",
5
<?php $nb1 = count($entity); $j = 0; foreach ($entity as $key => $value): ++$j ?>
6
"<?php echo $key ?>": <?php echo (is_object($value))?json_encode($value->getRawValue()):json_encode($value); echo ($nb1 == $j ? '' : ',') ?>
8
}<?php echo $nb == $i ? '' : ',' ?>
b'\\ No newline at end of file'