php - Replace tabs or multiple spaces -


i wanted check code valid trying (replaces tab(s) or multiple spaces 1 space.

preg_replace('/\t+|\s{2,}/', ' ', $street); 

however if found tab , space together, wouldn't end 2 spaces then? original space & new 1 tab got replaced with.

how can change spaces in string end being 1 space?

as \s match both tabs , spaces (as other forms of white-space), should trick replace amount of consecutive white-space single space:

preg_replace('/\s+/', ' ', $street); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -