Solved

Getting eval() to parse PHP open/close tags

Posted on 2009-04-06
6
337 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now