Dealing with a code tag

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Dealing with a code tag

Post by Cirdan »

So I'm implementing my own form of BBCode into my site, and need ideas of how to implement a code tag. Right now I just preg_replace the other tags, but this one is a bit more complicated.

What I was thinking was, I substr out the code tags into an array. Replace the code tags with something like {code1}. Format the code, then just replace {code1} with the code tag.

Seems like a clunky way to do it tho:

find first code tag
find first /code tag
substr
preg_replace with {code*}
replace needed html, only the first code tag tho
-repeat for every code tag
format text
replace each {code*} with the associated code in the text
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Dealing with a code tag

Post by watson516 »

You could do something like this.
Post Reply