I am using PHP 7.4.1
and want to remove double/triple/n-th whitespaces only between two words.
I tried:
<?php
$str = "Hello World!
This is my input string.";
$str1 = preg_replace('/ss+/', ' ', $str);
echo $str1;
echo "
###############################
";
$str2 = preg_replace('/[s]+/mu', ' ', $str);
echo $str2;
echo "
###############################
";
This on the one hand removes the whitespace, but on the other hand removes the two
.
I would like to have the following output:
Hello World!
This is my input string.
Any suggestions what I am doing wrong?
I appreciate your replies!
question from:
https://stackoverflow.com/questions/65861804/remove-only-whitespaces-between-words-but-leave-n 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…