【发布时间】:2012-01-20 06:40:29
【问题描述】:
我需要在新行上记录每个错误。
file_put_contents('PDOErrors.txt', $e->getMessage() . \n, FILE_APPEND);
这按预期工作,除了所有内容都保留在第一行,所以我尝试使用 \n 似乎不正确。
【问题讨论】:
标签: php string string-concatenation
我需要在新行上记录每个错误。
file_put_contents('PDOErrors.txt', $e->getMessage() . \n, FILE_APPEND);
这按预期工作,除了所有内容都保留在第一行,所以我尝试使用 \n 似乎不正确。
【问题讨论】:
标签: php string string-concatenation
你应该引用\n。
file_put_contents('PDOErrors.txt', $e->getMessage() . "\n", FILE_APPEND);
或者使用PHP_EOL常量。
file_put_contents('PDOErrors.txt', $e->getMessage() . PHP_EOL, FILE_APPEND);
【讨论】:
另一种方式:
file_put_contents('PDOErrors.txt', $e->getMessage().PHP_EOL, FILE_APPEND);
【讨论】:
您缺少引号。查看更多关于string concatenation in php的信息。
file_put_contents('PDOErrors.txt', $e->getMessage() ."\n", FILE_APPEND);
或者交叉兼容:
file_put_contents('PDOErrors.txt', $e->getMessage() .PHP_EOL, FILE_APPEND);
【讨论】: