我有这样一段代码文件:包括使用JSON
<?php
set_time_limit(0);
// arquivo cujo conteúdo será enviado ao cliente
$dataFileName = 'data.php';
while (true)
{
$requestedTimestamp = isset ($_GET [ 'timestamp' ]) ? (int)$_GET [ 'timestamp' ] : null;
// o PHP faz cache de operações "stat" do filesystem. Por isso, devemos limpar esse cache
clearstatcache();
$modifiedAt = filemtime($dataFileName);
if ($requestedTimestamp == null || $modifiedAt > $requestedTimestamp)
{
$data = file_get_contents($dataFileName);
$arrData = array(
'content' => $data,
'timestamp' => $modifiedAt
);
$json = json_encode($arrData);
echo $json;
break;
}
else
{
sleep(1);
continue;
}
}
正如你所看到的,我说$dataFileName = 'data.php'
再往下我做一个conten这等于data.php里面的数据。在data.php我不能因为某些原因显示PHP标签内的数据,但不过,我可以显示文本纯:
<?php
$hej = "This will not display";
return json_encode($hej);
?>
This will display
希望能帮到你,明白我的问题!
嗯,它不工作:( –
什么是输出?我试图打开文件并回显出来,它似乎工作正常。 – Kamehameha
即时通讯只获取不在php标签内的输出 –