【发布时间】:2013-04-18 17:16:49
【问题描述】:
我正在尝试在我的浏览器中测试一个函数,但没有返回任何内容。我访问了链接http://localhost/myfunctions.php?runFunction=writeJSON
我的功能是:
function writeJSON()
{
$myfile="testson.json";
$fileout=fopen($myfile,'w') or die("Fatal: Can't open JSON file for writing");
global $arrayForJSON;
if(isset($arrayForJSON))
{
fwrite($fileout,json_encode($arrayForJSON));
echo "done";
}
else echo "Error: could not write to JSON file";
fclose($myfile);
}
我在哪里弄错了,测试功能的正确方法是什么,或者我做错了什么?
该函数似乎没有运行,因为没有显示“完成”或“错误:无法写入 JSON 文件”,也没有对我的文件进行任何更改。
【问题讨论】:
-
是
echoing 吗? -
好吧,看来该功能没有运行。如何从
myfunctions.php中调用函数? -
这个函数在哪里调用?
-
这不是你调用 PHP 函数的方式。您需要在文件末尾添加类似
writeJSON()的行。 -
那我真的有问题了。有人告诉我,使用 runFunction=myFunction 在 URL 中传递它会执行我的函数。问题是我需要在其他地方单击按钮时运行代码