FabricioG
FabricioG

Reputation: 3320

Remove front and end white space from a string

I see this question has been asked a few times but I couldn't find an answer in php.

I have the following string.

$myString = "‍ LLC."

I run this trim($myString); and I get this back "‍ LLC." according to the trim documentation it should delete the white space in the front and the back? What am I missing?

I also tried htis trim($myString, " "); same results

Upvotes: 0

Views: 66

Answers (2)

revo
revo

Reputation: 48751

The e2808d at the beginning of bin2hex() output is ZERO WIDTH JOINER character and the reason for trim() to not trim it. Try (PHP 7):

echo trim($myString, "\u{200d} \t\n\r\0\x0B");

Upvotes: 2

Yassine Qoraiche
Yassine Qoraiche

Reputation: 1158

I think this is happening because of the empty space is not really a real white space (tab) looks like a hidden character (â). i copy your variable and value code into an online PHP editor and i got this:

enter image description here

Upvotes: 0

Related Questions