Page 1 of 1

eval() destroying line breaks

Posted: Tue Aug 25, 2009 5:56 am
by Hoth
Here's a tiny test script that illustrates the problem:

Code: Select all

<?php 
echo eval("?>line 1
<?php if (1) { ?>line 2<?php } ?>
line 3
 <?php ");
?>
The result is:

Code: Select all

line 1
line 2line 3
How do I get the

Code: Select all

line 1
line 2
line 3

result that I expect to get? I can't see why it's eating the line break after the condition.

Re: eval() destroying line breaks

Posted: Tue Aug 25, 2009 6:46 am
by jackpf
Read the bit after example 1 here: http://www.php.net/manual/en/language.b ... hpmode.php

Should explain why :)

Re: eval() destroying line breaks

Posted: Tue Aug 25, 2009 4:59 pm
by Hoth
Thanks. I guess the only way to deal with it is to double them, $doc = str_replace("<?php } ?>\n", "<?php } ?>\n\n", $doc); ? Seems an ugly hack.