How to Display PHP Code in my PHP Page?

Hello There,

I am trying to Develop a tutorial, and I like to display PHP Code on my page, so user can copy and paste it.

Can any one help me in simple term, how can I print PHP Code on my page, specially color coded (see example below). Any idea With Textarea Box as well as Without Textarea Box will be appreciated.

I like to display PHP Code as its displyed here: This is just an example


<?php

$path = "";
$max_size = 200000;

if (!isset($HTTP_POST_FILES['userfile'])) exit;

?>

replace < and > with < and >

StarLion Said: replace < and > with < and >

Thanks StarLion, I did not understand your response, by changing < and > displays < and >.

Here I tried Textarea Tag which works; but displyed code are not color coded. Can anyone help, please.

<textarea cols="150" rows="10">
$path = "";
$max_size = 200000;
		
	$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path . $HTTP_POST_FILES['userfile']['name']);
	if (!$res) 
	{ 
		echo "upload failed!<br>\
"; exit; } else { echo "upload sucessful<br>\
";
	}
	
	echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\
";
	echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\
";
	echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\
";
</textarea>

Color coding is an entirely different kettle of fish… and about 6 levels of complexity higher.

Not too many standard libraries of languages have this… but you’re in luck!

http://php.net/highlight_string

There’s the javascript syntax highlighter, which has any number of plugins based on it for various languages, CMSes, and libraries/frameworks.

http://php.net/manual/en/function.highlight-string.php


highlight_string('<?php phpinfo(); ?>');

Force Flow Said

http://alexgorbatchev.com/wiki/SyntaxHighlighter

There’s the javascript syntax highlighter, which has any number of plugins based on it for various languages, CMSes, and libraries/frameworks.

Thank you Force Flow, that is exactly what I need. Simple enough.

Once again, thank you very much.

Hello,

Apply the PHP function “htmlentities” to exchange everything positioned inside the CODEBOX bbcode.