Many sites do this by putting the code as the default information within a textarea tag. This also allows you to limit the actual size of the box on the page so that long code does not mess with your look and feel. The textbox will be scrollable allowing full viewing and copying.
2006-09-18 10:36:55
·
answer #1
·
answered by Interested Dude 7
·
0⤊
0⤋
So you want a script like and show it on the screen??? with out actually returning the word hello on the screen as html?
If it is, there are two ways. One is to use the proper syntax of < and > which are (WITHOUT SPACES):
& lt ;
& gt ;
so the above php code is (again, & gt ; and & lt ; wihtout spaces):
& lt ;?php echo "Hello"; ?& gt ;
also, a hint on the & gt; look at this page source code, and you see what I mean!
or you can use something called pre tags
so you have
The pre tags, I am not sure if they are html valid. So check www.w3.com if you are fussy at making your code valid.
or if you want php code to generate php code.. use this
" ?>
The reason why this works is because php works by scaning the file and then performing operation and transforming the document into an html format. Because this statement performs a operation, by the time is has finish the operation, in this case the echo, that echo string is now in an html format, and not a php code. Simple.
2006-09-18 10:33:08
·
answer #2
·
answered by cktan86 2
·
0⤊
0⤋
You could also use the function highlight_file($fileToShow) to view the source code. Just make sure you don't echo any sensitive files.
2006-09-19 03:23:33
·
answer #3
·
answered by Anonymous
·
0⤊
0⤋
echo('This will concatenate the values of the variables to the echo string' . $varname . 'The periods are used to concatenate (add) to a string in PHP!');
2006-09-18 10:39:56
·
answer #4
·
answered by Anonymous
·
0⤊
0⤋
If you create a file, and based on mime type, name it phps, and put your snippet in there, then you should be able to have them click it and download it.... otherwise, just end the php statement and type the code. this is my code; ?> this is the code sample code again ....
2006-09-18 10:33:21
·
answer #5
·
answered by rar 2
·
0⤊
0⤋
Use highlight_file() instead of echo:
http://www.php.net/highlight_file
__________
2006-09-20 05:18:16
·
answer #6
·
answered by NC 7
·
0⤊
0⤋