If you want to replace multiple space with single space from a string you can use preg_replace function for this. Refer the below example

preg_replace(“!\s+!”,” “,$yourstring);

For example
$yourstring = “This contain space”;
$modifiedString = preg_replace(“!\s+!”,” “,$yourstring);
echo $modifiedString;
// This contain space // output

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.