Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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 show_invisible(Object->numbers[0]) and it will show 123\n or similar?

like image 604
dukevin Avatar asked Feb 19 '12 01:02

dukevin


People also ask

How do you see invisible characters?

To show non-printing characters in Word, click the “Home” tab in the Ribbon. Then click the “Show/Hide Non-Printing Characters” button in the “Paragraph” button group.

Is there an invisible ascii character?

There is actually a truly invisible character: U+FEFF . This character is called the Byte Order Mark and is related to the Unicode 8 system.

How remove hidden special characters SQL?

Declare @nl Char(2) = char(13) + char(10) Declare @tab Char(1) = char(9) etc... Then you can use those declared variables anywhere in the rest of the proc without loss of clarity...


2 Answers

To see all the invisible characters not only \r, \n etc... It's good to see json_encodeed version and everything is clear:

$str = "..."; echo json_encode($str); 
like image 89
George Garchagudashvili Avatar answered Sep 24 '22 04:09

George Garchagudashvili


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.

like image 30
MyStream Avatar answered Sep 23 '22 04:09

MyStream