Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件“内容添加”;0“;不是字符串_Php - Fatal编程技术网

Php 文件“内容添加”;0“;不是字符串

Php 文件“内容添加”;0“;不是字符串,php,Php,是什么原因导致文件内容会添加0而不是传递给它的字符串 它会为每次尝试提交文件添加0。在第三次尝试中,我们得到了1000美元 $masterpostEntry = $title . "~" . $filetitle; $file = "../posts/master-allposts.txt"; $current = file_get_contents($file); $current .= $masterpostEntry + "\n"; file_put_contents($file, $cu

是什么原因导致文件内容会添加0而不是传递给它的字符串

它会为每次尝试提交文件添加0。在第三次尝试中,我们得到了1000美元

$masterpostEntry = $title . "~" . $filetitle;
$file = "../posts/master-allposts.txt";
$current = file_get_contents($file);
$current .= $masterpostEntry + "\n";
file_put_contents($file, $current);
$masterpostEntry的回显显示正确的结果:

CSS-Only Solution For UI Tracking~css-only-solution-for-ui-tracking
但是,master-allposts.txt的内容是:

000

基本PHP:
串联,
+
是算术:

$current .= $masterpostEntry + "\n";
                             ^---
您正在“添加”两个字符串,因此PHP将它们转换为整数。除非其中一个字符串的开头有一些数字,否则您将执行以下等效操作:

$current .= 0 + 0;

在PHP中,+是对concat的一个添加,使用点。

谢谢,我一直在PHP和JS之间切换,但没有注意到这一点。谢谢,我在PHP和JS之间切换时很愚蠢,弄糊涂了。