Jump to content

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>";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.