PHP fwrite写入0个字节

时间:2013-04-19 16:10:46

标签: php fwrite

我一遍又一遍地测试了这个,并且由于某种原因,代码在我的文件上写入0但是当我做回声时它会写出预期的文本。

这是我的代码:

<?
$author = $_POST["author"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if (isset($author) && isset($email) && isset($comment)) {
    $fileWrite = fopen("Archivo/comentarios.txt","a");
    $bytes = fwrite($fileWrite,$author + "*" + $email + "*" + $comment + "\n");
    fclose($fileWrite);
}

header('Location: http://www.empowernetworkmexico.com.mx/contacto.php');
?>

<html><head></head><body>
<?
    echo $author;
    echo $email;
    echo $comment;
?>
</body></html>

我使用“TEST”测试了我提交表单中每个参数的文本值。

2 个答案:

答案 0 :(得分:1)

+不是用于联合使用.。有关连接运算符的详细信息,请参阅此页面(&#39;。&#39;)http://www.php.net/manual/en/language.operators.string.php

 if (isset($author) && isset($email) && isset($comment)) {
   $fileWrite = fopen("Archivo/comentarios.txt","a+");
   $bytes = fwrite($fileWrite,$author . "*" . $email . "*" . $comment . "\n");
   fclose($fileWrite);
}

答案 1 :(得分:0)

php中的字符串连接运算符不是“+”而是“。”。看起来你有使用JS或Python的经验..

fwrite($fileWrite,$author . "*" . $email . "*" . $comment . "\n");