file_put_contents会添加0而不是传递给它的字符串是什么原因?
它为每次尝试提交文件添加0.所以000第三次尝试.
$masterpostEntry = $title . "~" . $filetitle;
$file = "../posts/master-allposts.txt";
$current = file_get_contents($file);
$current .= $masterpostEntry + "\n";
file_put_contents($file, $current);
Run Code Online (Sandbox Code Playgroud)
$ masterpostEntry的回显显示正确的结果:
CSS-Only Solution For UI Tracking~css-only-solution-for-ui-tracking
Run Code Online (Sandbox Code Playgroud)
但是master-allposts.txt的内容是:
000
Run Code Online (Sandbox Code Playgroud)
基本PHP:.连接,+是算术:
$current .= $masterpostEntry + "\n";
^---
Run Code Online (Sandbox Code Playgroud)
你正在"添加"两个字符串,因此PHP将它们转换为整数.除非其中一个字符串在字符串的开头有一些数字,否则你将做的相当于:
$current .= 0 + 0;
Run Code Online (Sandbox Code Playgroud)