I have a file that outputs JSON. I would like to capture this output in a second file. However, when I include the output file, nothing is getting captured and I'm wondering if ob_start does not work with JSON.
Output.php
The JSON output file outputs:
{"book":{"title":"Peter Pan","author":"JM Barrie"}}
The code that outputs it is:
echo json_encode(array('book'=>$book));
My code to capture this and print it from a second file is:
Bigpage.php
ob_start();
echo "got here"
include 'output.php';
$output = ob_get_clean();
echo $output; //prints "got here". Does not print out anything from output.php
What am I doing wrong? Alternatively, how should can I capture and print this output?
You have missing
;afterecho "got here", idk if that's the case. Im doing everything as you and the result is :Is it what you expect?