我有这个功能,它将内容写入文本文件:
function write($text){
fwrite($this->fp, '#' . date('H:i d.m.Y') . ': ' . $text . "\n\n");
}
Run Code Online (Sandbox Code Playgroud)
每次调用它时,都会添加文本并调用新行.
但如果我做了这样的事情:
$text = 'some text \n\n Some more text.';
write($text)
Run Code Online (Sandbox Code Playgroud)
然后文本中的换行符不是"正常".
这是为什么?我错过了什么?
这是我用来记录调试数据的整个函数:
class logDebuggData {
private $fp = NULL;
function __construct($name='log', $dir=''){
$this->fp = fopen(TEMPLATE_DIR.$name.'.txt', 'a+');
}
function write($text){
fwrite($this->fp, '#' . date('H:i d.m.Y') . ': ' . $text . "\n\n");
}
function close(){
if ($this->fp) {
fclose($this->fp);
$this->fp = NULL;
}
}
function __destruct() {
$this->close();
}
}
Run Code Online (Sandbox Code Playgroud)
您需要使用双引号而不是单引号:
$text = "some text \n\n Some more text.";
^ ^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70 次 |
| 最近记录: |