Page 1 of 1

use PHP code to print working PHP code

Posted: Sun Jul 06, 2003 11:30 am
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);

?>

Posted: Sun Jul 06, 2003 3:50 pm
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); 

?>

It Worked! sort of...

Posted: Sun Jul 06, 2003 8:40 pm
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.