I want to remove only multiple white space in a string.
Example:
I am Mert Inal , so[multible white space here]I[multible white space here]can do that
It's must be:
I am Mert Inal soIcan do that
I want to remove only multiple white space in a string.
Example:
I am Mert Inal , so[multible white space here]I[multible white space here]can do that
It's must be:
I am Mert Inal soIcan do that
Try using preg_replace
with the pattern \s{2,}
, and replace with empty string:
$input = "I am Mert Inal , so I can do that";
$output = preg_replace("/\s{2,}/", "", $input);
echo $output;
This outputs:
I am Mert Inal , soIcan do that
you can try
$string = "I am Mert Inal , so I ";
echo preg_replace('/\s+/', ' ',$string);
Output:
I am Mert Inal , so I .
Note:
/s is also applicable for \n\r\t.