Solved

Getting eval() to parse PHP open/close tags

Posted on 2009-04-06
6
333 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

920 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

15 Experts available now in Live!

Get 1:1 Help Now