kpetsche20 Posted July 16, 2008 Share Posted July 16, 2008 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/115032-how-do-i-display-php-code-on-a-html-page/ Share on other sites More sharing options...
trq Posted July 16, 2008 Share Posted July 16, 2008 Take a look at highlight_string(). Link to comment https://forums.phpfreaks.com/topic/115032-how-do-i-display-php-code-on-a-html-page/#findComment-591543 Share on other sites More sharing options...
kpetsche20 Posted July 16, 2008 Author Share Posted July 16, 2008 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? Link to comment https://forums.phpfreaks.com/topic/115032-how-do-i-display-php-code-on-a-html-page/#findComment-591548 Share on other sites More sharing options...
wildteen88 Posted July 16, 2008 Share Posted July 16, 2008 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>"; } Link to comment https://forums.phpfreaks.com/topic/115032-how-do-i-display-php-code-on-a-html-page/#findComment-591833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.