Condense multiple spaces in a string into a single space.
Source Code
$text = "This is a text with multiple spaces.";
$cleaned = preg_replace('/s+/', ' ', $text);
echo $cleaned; // Outputs: "This is a text with multiple spaces."
Condense multiple spaces in a string into a single space.
$text = "This is a text with multiple spaces.";
$cleaned = preg_replace('/s+/', ' ', $text);
echo $cleaned; // Outputs: "This is a text with multiple spaces."