PDA

View Full Version : Show a php code to a user


awsomejoe23
05-02-2007, 02:23 AM
I want to show a php code to a user. how would I do this? I know I can't use the code tags, is there a php tag(for a site, not forum)? Thanks

CFMaBiSmAd
05-02-2007, 02:46 AM
To display and color highlight PHP code, use either of the following functions -
http://www.php.net/manual/en/function.highlight-string.php
http://www.php.net/manual/en/function.highlight-file.php

awsomejoe23
05-02-2007, 03:38 AM
I keep getting a syntax error. What am I doing wrong?

<?php
$return= "true";
$str= "<?php
switch (rand(1, 4)){
case '1':
echo 'html goes here. This is item 1';
break;
case '2':
echo 'html goes here. This is item 2!';
break;
case '3';
echo 'html goes here. This is item 3';
break;
case '4';
echo 'html goes here. This is item 4';
break;

}

?>";
highlight_string ( string $str, $return );
?>

PappaJohn
05-02-2007, 03:55 AM
highlight_string ( string $str, $return );
should be
highlight_string ( $str, $return );

Pennimus
05-02-2007, 11:04 AM
That's a really cool function... but, is there any way of making it output classes instead of the deprecated <font> tag?

EDIT: Nevermind, found this class (http://web.archive.org/web/20060502152327/aidanlister.com/repos/v/PHP_Highlight.php) with improved highlighting and valid XHTML output.