PHP:有没有办法看到“不可见"的内容?像\ n这样的字符 [英] PHP: is there a way to see "invisible" characters like \n

查看:395
本文介绍了PHP:有没有办法看到“不可见"的内容?像\ n这样的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过诸如print_r()之类的方式查看不可见字符(如空格,换行符和其他非打印字符)?

Is there a way to see invisible characters like whitespace, newlines, and other non-printing characters in a manner like print_r() ?

原因是我的数组中有某种我看不见的字符并弄乱了东西.

Reason is there is some sort of character in my array that I can't see and breaking things.

Object Object
(
  [name] => name
  [numbers] => Array
      (
          [0] => 123

          [1] => 456
          [2] => 789
      )
   [action] => nothing
)

看到[0]和[1]之间的怪异空白吗?打印[0]时,也会换行.但是,我没有在哪里为[0]分配换行符,所以我很困惑.

See the weird whitespace between [0] and [1]? When printing out [0] a newline gets printed as well. But no where do I assign a newline to [0] so I'm quite confused.

在php中是否有类似于show_invisible(Object->numbers[0])的内置函数,它将显示123\n或类似内容?

Is there a built in function in php that's like show_invisible(Object->numbers[0]) and it will show 123\n or similar?

推荐答案

您可以使用

字符串addcslashes(字符串$ str,字符串$ charlist)

string addcslashes ( string $str, string $charlist )

,它将返回在字符前带有反斜杠的字符串.一个例子是:

which will return a string with backslashes before characters. An example would be:

<?php
echo addcslashes('foo[ ]', 'A..z');
// output:  \f\o\o\[ \]
// All upper and lower-case letters will be escaped
// ... but so will the [\]^_`
?>

这篇关于PHP:有没有办法看到“不可见"的内容?像\ n这样的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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