Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are functions like strip_tags() and trim() UTF-8 aware?

Tags:

utf-8

php-5.3

I'm wondering whether functions like strip_tags() and trim() UTF-8 aware?

I found this on the web, but I'm not sure about it:

strip_tags(): multi-byte UTF-8 characters contain no byte sequences that resemble less-than or greater-than symbols.

trim(): multi-byte UTF-8 characters contain no byte sequences that resemble white space.

If it's true, using those functions with an UTF-8 string could lead to a corrupted/illegible string.

Thank you.

like image 649
entropid Avatar asked Dec 01 '11 20:12

entropid


1 Answers

I think the descriptions you quoted mean just the opposite. Because utf8 multi-byte characters DON'T contains whitespace, or lt/gt, or any other byte < 0x80, you can safely use those functions on utf8 strings. That's the beauty of utf8!

like image 142
dschultz Avatar answered Sep 28 '22 02:09

dschultz