eval() destroying line breaks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hoth
Forum Newbie
Posts: 2
Joined: Tue Aug 25, 2009 5:53 am

eval() destroying line breaks

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: eval() destroying line breaks

Post by jackpf »

Read the bit after example 1 here: http://www.php.net/manual/en/language.b ... hpmode.php

Should explain why :)
Hoth
Forum Newbie
Posts: 2
Joined: Tue Aug 25, 2009 5:53 am

Re: eval() destroying line breaks

Post 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.
Post Reply