PHP error_log输出换行符为文字"\ n"; Mac OSX上的字符串 [英] PHP error_log outputting line breaks as literal "\n" strings on Mac OSX

查看:333
本文介绍了PHP error_log输出换行符为文字"\ n"; Mac OSX上的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些使用error_log()进行调试的代码.问题是由于某种原因,输出中的所有换行符都显示为原义的\n字符串,因此没有实际的换行符(使该死的几乎无法理解复杂的数组).
我尝试将var_exportprint_rerror_log函数一起使用,并且都得到了相同的结果:整个\n的文本块都分散了.我什至尝试对PHP_EOL进行str_replace \n都没有成功.我在做什么错了?

I'm working on some code that uses error_log() for debugging. The problem is that for some reason, all of the line breaks in the output appear as literal \n strings, so there's no actual line break (making it damn near impossible to comprehend complex arrays).
I tried using both var_export and print_r with the error_log function, and both led to the same result: a block of text with \n scattered throughout. I even tried doing str_replace \n to PHP_EOL with no success. What am I doing wrong?

要澄清:\n字符串出现在控制台错误日志查看器,TextEdit和终端中.

To clarify: the \n strings appear in the Console error log viewer, TextEdit, and the Terminal.

编辑

只是想提前指出,是的,我知道您需要对\n字符串加双引号,以使其显示为换行符.但是,我正在处理print_rvar_export的输出(以检查数组),所以这对我没有帮助(我认为吗?).

Just wanted to note in advance that yes, I'm aware that you need to double-quote \n strings for them to appear as line breaks. However, I'm dealing with the output from print_r or var_export (to inspect an array) so this doesn't really help me (I think?).

推荐答案

显然,此问题与您的操作系统无关.看到以下问题: PHP错误日志和换行符

Apparently, this issue is independent of your operating system. See this question: PHP error log and newline chars

...您应该能够在Debian上的php.ini中将error_log指令更改为指向文件.如果未定义,它将通过不支持多行的syslog.

...you should be able to change the error_log directive in your php.ini on Debian to point to a file. If this is undefined, it will go through syslog which doesn't support multiple lines.

这篇关于PHP error_log输出换行符为文字"\ n"; Mac OSX上的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆