Hello all!
What is the regular expression pattern to remove extra white spaces in the middle of strings (leaving just one)?
Regular Expressions (removing extra white spaces)
Moderator: General Moderators
-
Rafael Almeida
- Forum Newbie
- Posts: 5
- Joined: Thu Dec 16, 2004 10:21 pm
replace 2 or more consequtive spaces w/ a single space
Code: Select all
<?php
$pattern = '/(\s{2,})/';
$subject = 'foo bar baz';
echo preg_replace($pattern, ' ', $subject);
?>