Running PHP Script as a Python Script [StandAlone Script]
or Tagless script
1. Little slow
Write a Program to print expression based calculation
inorder to solve any expression we can use eval() function
to evaluate a expression as a string
Limitation of using eval()
eval() can be used to evaluate the expression as a string it may contain keyword
or varibles as string
for example
This is valid
$i=10;
eval("if($i==10){echo 'hello';}else{ echo 'hi';}");
php > $i=10;
php > eval("if($i==10){echo 'hello';}else{ echo 'hi';}");
hello
php > $i=8;
php > eval("if($i==10){echo 'hello';}else{ echo 'hi';}");
1. eval() does not support assignment operator if you try to execute this
then d`code() error is raised since it is parse error no output
is going to generate.
2. PHP community Itself Discourages the use of eval()
IT IS DANGEROUS TO USE EVAL
Advantage:
1.donot allow any script specially to run enclosed as <?php tag ?>
2. using eval() expression you donot required wrapper tags or Tag Container
ie is you need not wrap your code inside <?php Tag ?>
Example :
<?php echo 'Hello world' ?>
eval("<?php echo 'hello world'; ?>");
parse Error unexpected Eol at line no something unexecpted '<'
0 Comments