note 108772 deleted from function.eval by peehaa

From: Date: Mon, 09 Dec 2013 11:58:31 +0000
Subject: note 108772 deleted from function.eval by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197863@lists.php.net to get a copy of this message
Note Submitter: wbcarts at juno dot com ---- PHP? OR JUST TEXT? When I am testing code, sometimes I want to see the code ALONG WITH the output. For example, if I am testing this: for($i = 0; $i < 10; $i++) { $die1 = rand(1, 6); // roll die 1 $die2 = rand(1, 6); // roll die 2 $dieTotal = $die1 + $die2; echo "[$die1][$die2] = $dieTotal\n"; } I want to see the entire thing outputted to my browser like so: ---- starting from here ---- for($i = 0; $i < 10; $i++) { $die1 = rand(1, 6); // roll die 1 $die2 = rand(1, 6); // roll die 2 $dieTotal = $die1 + $die2; echo "[$die1][$die2] = $dieTotal\n"; } [5][2] = 7 [1][5] = 6 [5][1] = 6 [3][2] = 5 [3][6] = 9 [5][1] = 6 [6][6] = 12 [1][2] = 3 [4][5] = 9 [1][2] = 3 ---- all the way to here ---- With eval() AND a simple TEXT file, I can do that. Just copy the code you are testing into a 'test.txt' file. Note: NO PHP TAGS should be in this file, AND leave a couple of blank lines at the end of the file. Now in the PHP script, be sure to include the HTML <pre> tags like so: <pre> <?php include('test.txt'); eval(file_get_contents('test.txt')); ?> </pre> When the contents of 'test.txt' is ran through the include() function, PHP does not consider it PHP code -- this is because there are no PHP tags in the file and gets outputted straight to the browser. However, when the contents are run through the eval() function, that is a different story -- it is nothing but, pure PHP code!

« previous php.notes (#197863) next »