Kevin Duke Kevin Duke - 1 year ago 67
PHP Question

PHP: is there a way to see "invisible" characters like \n

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

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.

Is there a built in function in php that's like
and it will show
or similar?

Answer Source

You can use the addcslashes function:

string addcslashes ( string $str , string $charlist )

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

echo addcslashes('foo[ ]', 'A..z');
// output:  \f\o\o\[ \]
// All upper and lower-case letters will be escaped
// ... but so will the [\]^_`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download