Php – preg_replace: how to strip off all white space and  

PHPpreg-replaceregexwhitespace

how do I strip off all white space and  ?

I have this as a input in a wrapper I create,

[b]       bold       [/b]

so before turning the text to bold, i want to strip off all white spaces and &nbsp, and turn it into [b]bold[/b],

$this->content = preg_replace("/\[(.*?)\]\s\s+(.*?)\s\s+\[\/(.*?)\]/", 
                "[$1]$2[/$3]", 
                $this->content);

but it does not work! can you help please?

Best Answer

There is no need for a regex based solution. You can simply use str_replace as:

$input = "[b]       bold       [/b]";
$input = str_replace(array(' ',' '),'',$input);
echo trim($input); // prints [b]bold[/b]