Re: Wrapping code inside [code]xxx[/code] tags.
| From: | David Otton | Date: | Mon, 06 Oct 2003 09:29:48 +0000 |
| Subject: | Re: Wrapping code inside [code]xxx[/code] tags. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-165161@lists.php.net to get a copy of this message | ||
On Mon, 6 Oct 2003 10:06:44 +0100, you wrote:
>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.
I'd suggest using string-handling functions (explode, split, preg_split,
etc) to chop the incoming text into seperate code and text blocks.
Then use highlight_string() (not highlight_file()) on the code blocks.