Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

Getting eval() to parse PHP open/close tags

I need to parse a PHP script with eval() and I want it to echo content that is outside of <?php tags.

My code gives an error because it does not know what to do with stuff outside of PHP tags. How can I echo stuff that is NOT inside PHP tags so this does not break?
<?php
 
$code = '
	<h1>PHP Info</h1>
	<?php
	phpinfo();
	?>
	Done!
	';
 
eval($code);
 
?>

Open in new window

0
hankknight
Asked:
hankknight
  • 3
  • 2
4 Solutions
 
QualitySoftwareDevelopmentCommented:
Try this...
<?php
 
$code = '
	<h1>PHP Info</h1>
	'.
	phpinfo();
	.'
	Done!
	';
 
eval($code);
 
?>

Open in new window

0
 
QualitySoftwareDevelopmentCommented:
Sorry ... like this
<?php
 
$code = '
	<h1>PHP Info</h1>
	'.
	phpinfo()
	.'
	Done!
	';
 
eval($code);
 
?>

Open in new window

0
 
shobinsunCommented:
Hello,

Try with this code.

$code = '
        <h1>PHP Info</h1>
        <?php
        phpinfo();
       
        Done
        ';
 
eval($code);
 
?>


Regards.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
shobinsunCommented:
Hello,

In the above I removed the first "<?php".
 
Use the code exactly what it is

0
 
QualitySoftwareDevelopmentCommented:
This could also be the case:
Use you orginal code and then

eval(?>$code<?);
0
 
SPARC-DESIGNCommented:
this will do the trick
<?php
echo '<h1>PHP Info</h1>';
eval("?>" . phpinfo() . "<?");
echo 'done';
?>

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now