note 108772 added to function.eval

From: Date: Wed, 23 May 2012 22:26:10 +0000
Subject: note 108772 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-188178@lists.php.net to get a copy of this message
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! ---- Server IP: 192.41.42.26 Probable Submitter: 69.19.176.1 ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- https://master.php.net/note/edit/108772 Del: integrated -- https://master.php.net/note/delete/108772/integrated Del: useless -- https://master.php.net/note/delete/108772/useless Del: bad code -- https://master.php.net/note/delete/108772/bad+code Del: spam -- https://master.php.net/note/delete/108772/spam Del: non-english -- https://master.php.net/note/delete/108772/non-english Del: in docs -- https://master.php.net/note/delete/108772/in+docs Del: other reasons-- https://master.php.net/note/delete/108772 Reject -- https://master.php.net/note/reject/108772 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188178) next »