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
To see all the invisible characters not only \r
, \n
etc... It's good to see json_encode
ed version and everything is clear:
$str = "...";
echo json_encode($str);
To have an exact replication of the input string, without the surrounding "
and without serialization, use this wrapper for json_encode():
substr(json_encode((string)$string), 1, -1)
It does a string casting and removes the "
of the JSON standard.
You could probably list all the control characters out, but try this for a quick fix ?
PHP - print string with control characters
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 hexdump -C
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 [\]^_` ?>