how to delete 2 spaces or break line become one space?
here is my coding is break line str_replace
$finalresul开发者_StackOverflow社区t = "a<\n>b";
$strreplace = str_replace("\n", "", $finalresult);
echo $strreplace;
here is my coding is 2 spaces str_replace
$finalresult = "a b";
$strreplace = str_replace(" ", "", $finalresult);
echo $strreplace;
result1 :
a
b
result2 :
a b
my question is why my str_replace does not working at all ?
I'm not entirely sure why that is not working (it is for me), however if you want to replace all x amounts of spaces / linebreaks etc. with one space you could do this:
$result = preg_replace('/\s+/',' ',$input);
Your two examples on codepad (they work fine):
http://codepad.org/t3jR2azv
http://codepad.org/h3qiDzMD
精彩评论