开发者

how to delete 2 spaces or break line become one space?

开发者 https://www.devze.com 2023-04-08 06:15 出处:网络
here is my coding is break line str_replace $finalresul开发者_StackOverflow社区t = \"a<\\n>b\";

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

0

精彩评论

暂无评论...
验证码 换一张
取 消