use PHP code to print working PHP code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yi3artist
Forum Newbie
Posts: 4
Joined: Sun Jul 06, 2003 11:30 am

use PHP code to print working PHP code

Post by yi3artist »

I am testing a concept I would like to try wiht PHP. My ultimate goal is too have PageA print some info from PageB, but that info has some php code in it that i do not want executed until it is printed on PageA.

On a single page, I am testing the ability to store HTML and PHP code in a print statement within a user-defined function, then execute that function.

My problem is that I cannot get opening and closing PHP tags ( <? , ?> ) to be stored in a string. So when the function is executed, it gets confused when it sees <? and ?> within PHP code. If I take those out, then the function prints the information like html code, leaving a nasty mess of unused PHP code visible on the webpage.

Code: Select all

<? function foo () &#123; print '

<table>
<tr>
   <td><b>Items</b></td>
</tr>

// here i would like to have the function print " <? "

if ($sailboat)
&#123; print "
<tr>
   <td><li><font color=gray>&#1111;$sailboat] sail boat</font></td>
</tr>
"; &#125;

// here i would like to have the function print " ?> "

</table>

'; &#125; ; ?>

<?

foo();

mysql_close($conn);

?>
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

why dont you just use the char codes like so:

Code: Select all

<? function foo () { print ' 

<table> 
<tr> 
   <td><b>Items</b></td> 
</tr> 

<&#63; //<?

if ($sailboat) 
{ print " 
<tr> 
   <td><li><font color=gray>[$sailboat] sail boat</font></td> 
</tr> 
"; } 

&#63;>//?>

</table> 

'; } ; ?> 

<? 

foo(); 

mysql_close($conn); 

?>
yi3artist
Forum Newbie
Posts: 4
Joined: Sun Jul 06, 2003 11:30 am

It Worked! sort of...

Post by yi3artist »

That character code was a great idea! The page did print the code exactly liek I wanted, but because PHP parsed the information once, it won't go back and parse the code that was printed.

Yes character codes worked. But it proved my overall plan to be a failure. I shall use an alternative.

Thank You for your help.
Post Reply