Wrapping code inside [code]xxx[/code] tags.

From: Date: Mon, 06 Oct 2003 09:06:44 +0000
Subject: Wrapping code inside [code]xxx[/code] tags.
Groups: php.general 
Request: Send a blank email to php-general+get-165160@lists.php.net to get a copy of this message
Hi all, I have on my site a part where users' can submit articles and no doubt their articles will contain code. Code is wrapped inside of [code] tags, i.e. [code]<?php echo "hi"; ?>[/code] However, there is other text in the same article, so I need to format the code inside of the [code] and [/code] tags using htmlspecialchars, nl2br and highlight_file and the rest of the code needs to be formatted with nl2br, strip_tags and possibly stripslashes/wordwrap. A typical example: --- Count number of rows inside of MySQL table [code] <?php mysql_connect(host,user,pass); mysql_connect(db); $query = "SELECT * FROM table"; $result = mysql_query($query); $rows = mysql_num_rows($result); echo $rows; ?> [/code] Save the above code into a file called count.php --- The code inside of the [code] and [/code] tags needs htmlspecialchars, nl2br, highlight_file and the outside text needs nl2br, strip_tags, stripslashes/wordwrap. Sorry for being repetitive, but just need to make sure I make sense! Any ideas appreciated

« previous php.general (#165160) next »