开发者

keep the original string format after modified?

keep the original string format after modified?

$source1= "03aaa\r\n
04bbb\r\n
05ccc\r\n
04eee\r\n
05fff\r\n
04ggg\r\n
05hhh\r\n
08eee\r\n"

Can be

$source2= "03aaa04bbb05ccc04eee05fff04g开发者_运维知识库gg05hhh08eee"

I want to keep the original format(if there are linebreak keep it like origin) after I made modified(added 07) the $source .

if input is like source1 format:

ouput:

$source1= "03aaa\r\n
  04bbb\r\n
  05ccc\r\n
  04eee\r\n
  05fff\r\n
  07fff\r\n
  04ggg\r\n
  05hhh\r\n
  07hhh\r\n
  08eee\r\n"

if input is like source2 format:

$source2= "03aaa04bbb05ccc07fff04eee05fff07fff04ggg05hhh007fff8eee"

How Can I got the expected result and keep the format like the origin?

Anyone could help me please?

thanks


Use single quotes to avoid translating special characters and variables.


If you want to compare the strings $source1 and $source2, you could do so as such:

if (str_replace("\r\n", "", $source1) == $source2)
{
    // Do your thing
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜