这是我的shell脚本的PHP代码:
#!/usr/bin/php -q
<?php
$user = get_current_user();
$line = date("c") . " - " . $user + "\r\n";
echo "---------------------\n";
echo "user => $user\n";
echo "---------------------\n";
echo "date('c') => " . date("c") . "\n";
echo "---------------------\n";
echo "date('Ymd') => " . date("Ymd") . "\n";
echo "---------------------\n";
echo "line => $line\n";
echo "---------------------\n";
echo date("c") . " - " . $user + "\n";
echo "---------------------\n";
echo date("c") . $user + "\n";
echo "---------------------\n";
echo date("c") . " - " . "\n";
echo "---------------------\n";
$ret = file_put_contents("/var/lib/foo/bar/test.txt", $line, FILE_APPEND);
echo "file_put_contents => $ret\n";
?>
当我运行它时,我得到了这个输出:
roffle:/var/lib/foo/bar # php Test.php
---------------------
user => wwwrun
---------------------
date('c') => 2014-07-27T16:39:34-04:00
---------------------
date('Ymd') => 20140727
---------------------
line => 2014
---------------------
2014---------------------
2014---------------------
2014-07-27T16:39:34-04:00 -
---------------------
file_put_contents => 4
roffle:/var/lib/foo/bar #
为什么$line
会与前两次调用echo date("c")
一起截断,为什么第三次调用date("c")
会好吗?
答案 0 :(得分:1)
看起来你只是混淆了+。用于连接相关行。