修改后保留原始字符串格式?

keep the original string format after modified?

$source1= "03aaa

04bbb

05ccc

04eee

05fff

04ggg

05hhh

08eee
"

Can be

$source2= "03aaa04bbb05ccc04eee05fff04ggg05hhh08eee"

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

  04bbb

  05ccc

  04eee

  05fff

  07fff

  04ggg

  05hhh

  07hhh

  08eee
"

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("
", "", $source1) == $source2)
{
    // Do your thing
}