Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is php trim mb safe

I know that there is no mb_trim version of the trim. I have links to the dozen of articles for how to implement one using preg_replace.

The question I have, is the usual trim with default chars mb safe? That is, is there any example of multibyte character that ends with single byte whitespace char code?

like image 859
loshad vtapkah Avatar asked Dec 27 '25 18:12

loshad vtapkah


1 Answers

Since characters in default character mask (whitespace+\t\n\r\0\x0B) are ASCII, it is safe to use trim() with multibute string.

trim('  漢字は  '); // ok

Character mask with multibyte characters will cause problems.

trim('はは漢字はは', 'は'); // bad
like image 200
Alexey Chuhrov Avatar answered Dec 30 '25 07:12

Alexey Chuhrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!