Jump to content

How do I display PHP code on a HTML page


kpetsche20

Recommended Posts

How do I display php code Like below on a HTML or PHP page? I want to view the code, not make it function

 

<?php 
if(isset($_POST['submit']))
{
$pagenum = $_POST['numberofpages'];
if($pagenum ==1)
{
echo "Value = 1";
}
}

else
{

echo "
<form name=\"addpage\" action=\"addpage.php\" method=\"POST\">
<select name=\"numberofpages\">
<option value=\"1\">1</option>
<option value=\"2\">2</option>
</select>
<br>
<input type = \"submit\" name=\"submit\" value=\"submit\">
</form>";
}
?>

Cool, that works, but I face a new problem.  I am making a form that generates PHP code based on the values I give, Table Name, Page Name, etc.

 

So I need to be able to have values of some variables display in the PHP code that is viewable, is this possible?

You'll first need to define the generated code within a string. Example

<?php
if(isset($_POST['submit']))
{
    $code  = '<?php' . PHP_EOL;
    $code .= '$pages = ' . $_POST['numberofpages'] . PHP_EOL;
    $code .= '?>';

    echo '<p>' . highlight_string($code, true) . '</p>';
}
else
{
    echo "<form name=\"addpage\" action=\"test.php\" method=\"POST\">
<select name=\"numberofpages\">
<option value=\"1\">1</option>
<option value=\"2\">2</option>
</select>
<br>
<input type = \"submit\" name=\"submit\" value=\"submit\">
</form>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.