I'm trying to replace multiple spaces with a single space. When I use ereg_replace
, I get an error about it being deprecated.
ereg_replace("[ \t\n\r]+", " ", $string);
Is there an identical replacement for it. I need to replace multiple " "
white spaces and multiple nbsp
white spaces with a single white space.
This question is related to
php
regex
formatting
string-formatting
ereg-replace
preg_replace("/[[:blank:]]+/"," ",$input)
$output = preg_replace('/\s+/', ' ',$input);
\s is shorthand for [ \t\n\r]
. Multiple spaces will be replaced with single space.
Source: Stackoverflow.com