PDA

View Full Version : BB Code using PHP?


Jibba Jabbas
05-30-2008, 10:02 PM
How do i go about using PHP when creating new BB Codes? Basically i want to create a new BB Code and i need to use the text between it in a PHP script...

So the process is like this:

test[bbcode]

Then a PHP script is run which has say $x = the user input.. in this case "test".

Then i after using that input to gather the relevant data i have it all in $a and want to print the contents of $a on the screen.

So it goes from [bbcode]test to showing the contents of $a.

How do i go about doing this?

Thanks

Attilitus
05-30-2008, 11:11 PM
It is easy if you know regular expressions. Here is the code you need: (Assuming that the code between the tags will be a string that doesn't contain whitespace.

preg_match_all("#\(\w+)\[\/bbcode\]#i",$template,$matches);

foreach($matches[0] as $value){
//$value contains the each instance of entire blocks matched "[bbcode]stringWithoutWhitespace"
}

foreach($matches[1] as $value){
//$value contains each instance of only stringWithoutWhitespace between the tags.
}



I hope this is helpful.

Jibba Jabbas
05-31-2008, 10:38 AM
But can that be input into the HTML box when you create a new bbcode using admin cp?

Once i get the bit in the middle i need to do something with it through PHP then the output needs to go onto the page.

Thanks