How to echo a string which contains <?php ?> -


i want generate php page contains html , php commands. problem when submit code below, output

<?php echo '$stfromyearerr  '?><?php echo '$stfrommontherr  '?><?php echo '$stfromdayerr  '?> <?php echo '$sttoyearerr  '?><?php echo '$sttomontherr  '?><?php echo '$sttodayerr  '?> 

rather php commands. how fix this?? thanks!!

<?php  $page = "<html lang='en'> <head> <meta charset='utf-8' /> </head> <body><table width='990' border='0' align='center'><tr><td width='54%' colspan='2'> <span class='error'>&lt?php echo '\$stfromyearerr &nbsp;';?&gt&lt?php echo '\$stfrommontherr &nbsp;';?&gt&lt?php echo '\$stfromdayerr &nbsp;';?&gt &lt?php echo '\$sttoyearerr &nbsp;';? &gt&lt?php echo '\$sttomontherr &nbsp;';?&gt&lt?php echo '\$sttodayerr &nbsp;';?&gt</span></td> </tr></table> </body></html>";   echo $page;  ?> 

you're echoing out php tags &lt;?php, , presumably displaying in browser. look php code in browser, because browsers render &lt; < it's not php code. it's text.

php not recursively executable, e.g.

<?php    echo "<?php echo 'foo '; ?>"; ?> 

would echo out <, ?, p, etc..., not foo.

you can stuff

<?php      $foo = "<?php echo 'hello world!'; ?>";     file_put_contents('hello.php', $foo); ?> 

without issues. long file you're producing gets executed php (e.g. don't name "hello.html"), php not know (or care) script produced other php code.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -