FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


need help with bbcode.....





salman_500
hey guyz..

you see i just did this new bbcode thingy on my forum...

but i cant figure one thing out.... you see i also included a quote option... so i want is that once people quote... the message comes in the post area of posting... just like here....

i managed to do this bit... by this method...

1) i get the user to press quote button send the id of post in URL.
2) the next posting page checks for the existance of "quote=id" in the URL.
3) it then sends a query that extracts relevant info from the table..
4) and then displays the extracted message as default of the text area..

now all this is done... but as the bbcode converts all stuff to html... the post area shows this..

Code:
[quote]test <b>bold </b><br /><br />
<br /><br />
[url]www.example.com[/url][/quote]<br>



where it should not display "<br>" and not show other stuff like.. in quote... it displays all the css and stuff....

so how can i get it to not to do this...... this si the bb code im usin...

Code:
<?php
function bbcode($string){

$string = nl2br(htmlspecialchars($string));

$patterns = array(

                                    '`\[b\](.+?)\[/b\]`is',
                                    '`\[i\](.+?)\[/i\]`is',
                                    '`\[u\](.+?)\[/u\]`is',
                                    '`\[strike\](.+?)\[/strike\]`is',
                                    '`\[color=#([0-9]{6})\](.+?)\[/color\]`is',
                                    '`\[email\](.+?)\[/email\]`is',
                                    '`\[img\](.+?)\[/img\]`is',
                           '`\[code\](.+?)\[/code\]`is',
                                    '`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
                                    '`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
                                    '`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',
                                    '`\[flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is',
                                    '`\[quote\](.+?)\[/quote\]`is',
                                    '`\[indent](.+?)\[/indent\]`is',
                                    '`\[size=([1-6]+)\](.+?)\[/size\]`is',
                           '`\[step\](.+?)\[/step\]`is'
                                 

                                );

$replaces =  array(

                                    '<b>\\1</b>',
                                    '<em>\\1</em>',
                                    '<u>\\1</u>',
                                    '<strike>\\1</strike>',
                                    '<span style="color:#\1;">\2</span>',
                                    '<a href="mailto:\1">\1</a>',
                                    '<img src="\1" alt="" style="border:0px;" />',
                           '<br><b><div align="left"><blockquote>Code:</blockquote></div></b><code><div align="left"  style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px solid #CCCCCC;width:90%;"><font color="#000000">\\1</font></div></code><br>',
                                    '<a href="\1\2">\6</a>',
                                    '<a href="\1\2">\1\2</a>',
                                    '<a href="http://\1">\1</a>',
                                    '<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>',
                                    '<b><div align="left">Quote</blockquote></div></b><div align="left" style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;width:90%;font:#000000;"><em><font color="#000000">\1</font></em></div>',
                                    '<pre>\\1</pre>',
                                    '<h\1>\2</h\1>',
                           '<br><br><br><img src="Templates/Urbane/images/tuts/\\1.gif"><br><br>',
                                     
                                     

                                    );


$string = preg_replace($patterns, $replaces , $string);

return $string;
}
?>



thnx in advance !!
hexkid
salman_500 wrote:
as the bbcode converts all stuff to html... the post area shows this..

Code:
[quote]test <b>bold </b><br /><br />
<br /><br />
[url]www.example.com[/url][/quote]<br>



where it should not display "<br>" and not show other stuff like.. in quote... it displays all the css and stuff....

so how can i get it to not to do this......

Well ... it all depends on what you have in the database. You have to edit the stuff you write into the textarea before sending it to the client. So let's say you have
Code:
$textarea_stuff = 'data_from_sql';
and this $textarea_stuff has bbcode (or html) embedded. Just get rid of it:
Code:
<?php
### echo "<textarea>$textarea_stuff</textarea>";
echo "<textarea>", remove_formatting($textarea_stuff), "</textarea>";
?>
where remove_formatting() is a function you have to write that formats whatever is in the database to whatever you want to display in the textarea, for example:
Code:
<?php
function remove_formatting($txt) {
  return strip_tags($txt);
}
?>


[Edited spelling]
salman_500
hey..


i just used strip tags... its removes all the html and stuff...

but when i quote a quoted message.... i dont know how to show the quote or code tags within a quotet message....

one thing i though of.... abave i pasted the bb code... is it possible that i reverse the bbcode or somthin ... and name the function "unbbcode" or somthin... which would match the html of the code or quote and then convert it to bbcode signs....... can you please assist me with this...


one more thing i though of was that i simply create another column in the table that would would contain the original post... like without converting it into html and when peoplw quote the message... i just extract the original code??

please help... if you can help me with the first idea.....then please do so.... i will really appreciate it..... but if incase there is no other solution... then i will just use the second idea...

thnx in advance !! Very Happy
hexkid
I hate bbcode!

What do you save to the database; bbcode or HTML?
It appears you save HTML, so either of your solutions is workable (no, i will not write an unbbcode() function).

One other thing you could have done (and can still, though you will have to convert your existing data) is to save bbcode to the database and parse it every time you display it, except for quoted text. If your server is heavily used the extra processing time can be an annoyance Sad
salman_500
hexkid wrote:
I hate bbcode!

What do you save to the database; bbcode or HTML?
It appears you save HTML, so either of your solutions is workable (no, i will not write an unbbcode() function).

One other thing you could have done (and can still, though you will have to convert your existing data) is to save bbcode to the database and parse it every time you display it, except for quoted text. If your server is heavily used the extra processing time can be an annoyance Sad




hmm... oh then... i guess i will work it with my second idea....

thnx though......

yup've been a great help.... not now... but everytime i asked somthin......

im very very thankful !! Very Happy Cool Cool
Related topics
can i help?
help,Bonding
HELP!!
Help me with MySQL Account Maintenance and phpBB 2.0.15 :((
help, change pass my acc in cpanel
help me upgrade php to 5.
Need help adding a domain
help add admin in phpbb forum
How to solve this problem? Thanks
Help!
Programming Help & Support Guidelines
BBcode Problem implementing??
Help would be nice
For Newbies: Help for BBCodes
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.