Solved

Getting eval() to parse PHP open/close tags

Posted on 2009-04-06
6
350 Views
Last Modified: 2012-05-06
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
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:QualitySoftwareDevelopment
ID: 24076965
Try this...
<?php
 
$code = '
	<h1>PHP Info</h1>
	'.
	phpinfo();
	.'
	Done!
	';
 
eval($code);
 
?>

Open in new window

0
 
LVL 3

Assisted Solution

by:QualitySoftwareDevelopment
QualitySoftwareDevelopment earned 275 total points
ID: 24076969
Sorry ... like this
<?php
 
$code = '
	<h1>PHP Info</h1>
	'.
	phpinfo()
	.'
	Done!
	';
 
eval($code);
 
?>

Open in new window

0
 
LVL 14

Assisted Solution

by:shobinsun
shobinsun earned 25 total points
ID: 24077030
Hello,

Try with this code.

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


Regards.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 14

Expert Comment

by:shobinsun
ID: 24077043
Hello,

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

0
 
LVL 3

Accepted Solution

by:
QualitySoftwareDevelopment earned 275 total points
ID: 24077079
This could also be the case:
Use you orginal code and then

eval(?>$code<?);
0
 
LVL 3

Assisted Solution

by:SPARC-DESIGN
SPARC-DESIGN earned 200 total points
ID: 24101190
this will do the trick
<?php
echo '<h1>PHP Info</h1>';
eval("?>" . phpinfo() . "<?");
echo 'done';
?>

Open in new window

0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL-Design Help 12 67
A responsive image gallery using flexbox 6 79
Last 4 numbers of a variable 9 22
Tell me if I understand this correctly... 6 20
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question