Page 1 of 1
Showing source
Posted: Wed Jul 02, 2003 2:23 am
by Czar
What is the best way to show code on php page, like code snippets here(ew). I load the source to DB and read it from there and i want to show the source code so, that code won't be parsed, not even html. Oh, and also; How to keep line breaks in right place so, that the code block wouldn't look like a table with a thousand characters in it?
Thanks.
BTW. The code doesn't have to be highlighted.
Posted: Wed Jul 02, 2003 3:23 am
by Phodetheus
Hi
First off make sure you omit the <? or <?php tag that tells the server to run your code, that will cause your code to be displayed.
If you surround the code in the <PRE></PRE> tag this will keep the code looking exactly as you have it in the source with line breaks and all.
Posted: Wed Jul 02, 2003 3:46 am
by Drachlen
Ripped from PHPBB:
Code: Select all
<?php
preg_replace('#(<)([\/]?.*?)(>)#is', '<\2>', $variable);
?>
Posted: Wed Jul 02, 2003 4:25 am
by pootergeist
another useful tag (for html) is <xmp> </xmp> which turns off the browsers html interpreter while active
so
<xmp><b>bold</b></xmp>
would show <b>bold</b> on the page.
to get php to nicely colour the code, just output the string through an
echo highlight_string($data); call.
Posted: Wed Jul 02, 2003 8:05 am
by m3rajk
http://www.w3schools.com/xhtml/xhtml_reference.asp
http://www.w3schools.com/html/html_reference.asp
those links have the html/xhtml tags. i know there's multiple tags that will work. pic one that works with both, because html is being deprecated for xhtml
and you need to replace the < with < and > with >
Posted: Wed Jul 02, 2003 11:09 am
by patrikG
Also the PHP-functions
highlight_file() and
highlight_string() are useful. They basically display PHP-code exactly the same way as phpBB (e.g. this board).