我想要做的是响应一个 JSON 数组的 PHP 文件输出。
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);
该文件view/item.php包含一些 PHPecho语句,但问题是响应包含include语句的输出和 JSON 编码项。
如何让脚本只返回 JSON 部分?