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 (  => 123  => 456  => 789 ) [action] => nothing )
See the weird whitespace between  and ? When printing out  a newline gets printed as well. But no where do I assign a newline to  so I’m quite confused.
Is there a built in function in php that’s like
show_invisible(Object->numbers) and it will show
123\n or similar?
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:
<?php echo addcslashes('foo[ ]', 'A..z'); // output: \f\o\o\[ \] // All upper and lower-case letters will be escaped // ... but so will the [\]^_` ?>
To see all the invisible characters not only
\n etc… It’s good to see
json_encodeed version and everything is clear:
$str = "..."; echo json_encode($str);
You could probably list all the control characters out, but try this for a quick fix ?
It’s a simple
str_replace("\n",'\n',$string) kind of fix, but you could probably adapt the solution for a function callback on the array to convert those characters.
You could just run your php script, and pipe it straight to
To have an exact replication of the input string, without the surrounding
" and without serialization, use this wrapper for
substr(json_encode((string)$string), 1, -1)
It does a string casting and removes the
" of the JSON standard.