Php 文件“内容添加”;0“;不是字符串
是什么原因导致文件内容会添加0而不是传递给它的字符串 它会为每次尝试提交文件添加0。在第三次尝试中,我们得到了1000美元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
$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之间切换时很愚蠢,弄糊涂了。