Multibyte trim in PHP?

后端 未结 8 1540
小鲜肉
小鲜肉 2020-11-28 08:19

Apparently there\'s no mb_trim in the mb_* family, so I\'m trying to implement one for my own.

I recently found this regex in a comment in php.net:

8条回答
  •  一生所求
    2020-11-28 09:22

    I don't know what you're trying to do with that endless recursive function you're defining, but if you just want a multibyte-safe trim, this will work.

    function mb_trim($str) {
      return preg_replace("/^\s+|\s+$/u", "", $str); 
    }
    

提交回复
热议问题