只有第37行的elseif (isset($foo['read']))
正常工作,if
和第一个elseif
正常工作,当我尝试调用第二个elseif
时,它会返回第一个elseif
1}}语句输出。我甚至交换了两个elseif
语句,它在调用第二个elseif
语句时仍然只返回第一个elseif
语句输出。
<?php
$nh = "true";
$foo = file_get_contents("php://input");
//$stuff = json_decode($foo, true);
function savetxt($sttext)
{
$filename = 'test.txt';
$somecontent = $sttext;
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
}
else {
echo "The file $filename is not writable";
}
}
if (strpos($foo, 'write:') !== false) {
echo 'Attempting to write!';
$stext = substr($foo, 6);
savetxt($stext);
}
elseif ($foo == "read"){
echo file_get_contents( "test.txt" );
}
elseif ($foo == "test){
echo 'Working!';
}
else {
echo 'Didn't get test.';
}
?>
答案 0 :(得分:0)
试试这个(你必须用else替换else if)
else if ($foo && $foo=='read')
和
else if ($foo && $foo=='test')
并在结束时
else if (!$foo || $foo=='')