I hope you will know what i'm talking about.
In phpBB forums the quoting is done by the tag quote (Like here) but it puts the quote in a box.
The quetion is how do I do that tag (Or any other tag while we're at it) and how does the whole quoting buesniss goes?
Quoting and BB code
i think i got what you mean. if so, it is mostly done using regular expressions. here is an example find quote tags and reformatting it.
<?php
$post = "[ QUOTE]this is something someone else said.[/ QUOTE] and then the rest of the text";
$post = preg_replace("/\[QUOTE\](.*?)\[\/QUOTE\]/s", "<font size=\"2\">Quote</font><hr align=\"left\" width=\"80%\">\\1<hr align=\"left\" width=\"80%\">", $post);
echo $post;
?>
see [man]preg_replace[/man] for more info.
Thanks I really needed that.
My next questiong is if I should use the regular expressions code after or before the messege is entered to the DB?
Best if its done when displaying to the user so no not before its added to the database but rather retrieved that way say in a forums case a user wants to update their post they dont see html but rather the bbcode
Yeah, I figured that out, I don't want the user to deal with any HTML.
Last question, why doesn't this code work?
$Text=preg_replace("/\[ Quote\](.*?)\[\/ Quote\]/s","Q uote:<br><td class=\"q\">$Text</td>",$Text);
Don't look at the spaces, something is wrong with the forum here.
yeah ive found it necessary to put regular expressions in [ CODE] tags instead of [ PHP] tags because the php tags seem to strip the escape backslashes, so its hard to tell what is wrong with that line since they are missing.
well it was a little easier to see than i thought. the reason its not working as far as i can see is because you put $Text in the second parameter. if you wanted the text in (.*?) to be there, you need to either use $1 or \1 to show the matched text.
with regular expressions, either preg_match or preg_replace, anything inside ( ) is going to be saved by php and put into special variables.
so if you have the pattern
/<a href=\"(.?)\">([>])</a>/
there the text in the first (.?) will go in $1 or \1, and ([>]) will go in $2 or \2. that way you can reference the text that was captured. in preg_match, it actually lets you specify an array for the matches to go in, so the case would be $matches[1] or $matches[2], \0 $0 or $matches[0] will always contain the full string that was matched.
see the php manual on regular expressions