In a text area, I want to show the PHP code for a script, but I only see the HTML output, instead of the plain source code. How can I get this plain PHP code to display?
For this purpose, I use a small Javascript component, that not only is very usefull, it also embeded the textarea into a nice IDE design with print and copy paste functionnalities. You can see a sample and download it at http://code.google.com/p/syntaxhighlighter/
You can use html special characters in the text in the content. for eg. <form action="test.php" method="post"> <textarea rows="5" cols="25" > <?php echo "Welcome to the world"; ?> </textarea> </form> Try this one
I have been struggling with this for such a long time... if only I had known it was this easy Thanks for the help!
<textarea rows="x" cols="y" > <?php highlight_file('/path/to/your_source_file.ext'); ?> </textarea> Code (PHP): OR <textarea rows="x" cols="y" > <?php $var = "Your source PHP here. Attention to \" splash or others like \$ , etc."; highlight_string($var); ?> </textarea> Code (PHP):
<textarea> <?php echo '<php //This is the PHP code I want to output echo "All this code will appear in plain text because it is in single quotes"; '; </textarea> HTML: It is easy as you can see. You should also search for phtml files and this php functions to output a files source in syntax highlighted format. http://us.php.net/manual/en/function.highlight-file.php
My website has a code snippets section and I use the following code to output the php codes in a textarea: <textarea> <?php echo(htmlspecialchars('<?php echo 'foo'; ?>')); ?> </textarea> PHP: