4

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?

loshad vtapkah
  • 429
  • 4
  • 11

1 Answers1

1

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
Alexey Chuhrov
  • 1,787
  • 12
  • 25