I need to write the following output in PHP:
var data = { "count": 1, "elements": [{"id": 1, "title": "title123", "url": "x123.php", "file_url": "x124.jpg"}]}
I have tried:
$txt = 'var data = { "count": 1,"elements": ';
$txt = $txt + '[{"id": 1, "title": "title123", "url": "x123.php", "file_url": "x124.jpg"}';
$something = json_encode($txt);
echo $something;
//
$something = print_r($txt);
echo $something;
//
$something = print_r(json_decode($txt));
echo $something;
//
ob_start;
var_dump($txt);
$something = ob_get_contents();
ob_end_clean();
echo $something;
I also have tried this:
$txt = '?var ?data ?= { "count": 1,"elements":';
for ($x = 0; $x <= strlen($txt); $x++) {
$neso = substr($txt,$x,1);
if ($neso != "?") {
echo "+" + $neso + "+" + $x;
}
}
Unfortunately I can not get any solution. All I get is 0 (zero) or 1 (one).
How can I get this output?