php removing excess whitespace

后端 未结 4 1415
天涯浪人
天涯浪人 2020-12-16 14:55

I\'m trying to remove excess whitespace from a string like this:

hello        world

to

4条回答
  •  盖世英雄少女心
    2020-12-16 15:55

    Not a PHP expert, but his sounds like a job for REGEX....

    
    

    Again, PHP is not my language, but the idea is to replace multiple whitespaces with single spaces. The \s stands for white space, and the + means one or more. The g on the end means to do it globally (i.e. more than once).

提交回复
热议问题