What I'm trying to do is to response with a JSON array of output of PHP files.
header("Content-Type: application/json");
$ret["response"] = array();
$items = getItems();
$ret["response"] = array();
ob_start();
foreach($items as $model){
include("view/item.php");
$ret["response"][] = ob_get_contents();
ob_end_clean();
}
ob_end_clean();
echo json_encode($ret);
the file view/item.php
contains some PHP echo
statements, but the problem is that response contains the output of include
statement and the JSON encoded items.
how do i make the script return only the JSON part?