PHP - Bbcode Problem
Hi there,
This isn't really a bbcode parser problem, but it kind of is. And I am awful at explaining things, as you have noticed. The problem is that I'd like to allow input for the main page of a site. But the part has this structu Code: [Select] <div class='mainheader'>TITLE</div> <div class='content'> The content of the webpage blabla</div> I'd like this whole page to be changeable, so also the title and the content. But how can I ensure that people use the content div after the mainheader div? I would like it if it were possible that they only needed to 'select' the header, how can I do this? Thanks in advance! Similar TutorialsEverything works fine, unless I add this stupid thing to get rid of people using HTML Code: [Select] $text = pun_htmlspecialchars($text); Once I add that to my function, no bbcodes work at all? But I cant use html.. (which is good) but I need to beable to use BBCODE, and parse hackers from using html also, any help? MY CODE absolutely destroyed the forum page here it is: http://pastebin.com/jv7m47kn Hello guys, i need help with my BBcoding ... Its about browser game.. but i need someone who has some time to listen me about how things work and than help me.. every time i put : when sending message ingame i automaticly get smiley ... but please if anyone have time let me know Best Regards Hey, I need help with my BBCode function... im trying to allow it to embed you tube videos but im kinda confused as to how i can do it when i need the link to be in the bbcode html ouput twice with my current method. Here is my function: http://www.paste.to/MzE3Mg== I could not post the script as it was messing up with this site's BBcode. Any one can help me please ? Thankss when posting a new message on my forum and it contains a url. How do i automatically add the bbcode url tags to a url in the message? I'm trying to work on BBCode for a forum. I have this: Code: [Select] <?php $bb_Code = array( '[ code]' => '<code>', '[ /code]' => '</code>' ); foreach ($bb_Code as $value => $replace) { $text = str_replace($value, $replace, $text); } ?> Question is.. how would I get it so when I insert information into the database it gets cleaned (strip_tags, etc.) but doesn't disturb what is in the [ code ] tags? So basically it makes the html, etc. in the [ code ] tags just plain text? Thanks in advanced. ok bare with me if this sounds stupid. How do i get it so that bbcode can be added within a textarea tag? im assuming it is a lot of str_replace. is there a tutorial on this somewhere? I was wonder how I could make some BBcode for my messaging system I made for a website. I made some simple ones like just by replace [ red ] with font color etc. I want to know how to do something like this: [ url = http://google . ca] Google [ / url ] without the spaces. ~AJ i am wanting to add a code tag to my bbcode list. Anything within this tag will be printed as is(like the html code). I have tried using htmlspecialchars() but it isnt printing the code. Here is the parser section for the tag: $patern = "#\[code = ([^\]]*)\]([^\[]*)\[/code\]#i"; $replace = "<table class=\"code\"> <tr> <th>\\1</th> </tr> <tr> <td>".htmlspecialchars('\\2')."</td> </tr> </table>"; $str=preg_replace($patern, $replace, $str); Any ideas? This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=354638.0 I have this function: function bbcode($input){ $input = strip_tags($input); $input = htmlentities($input); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url=http://(.*?)\](.*?)\[\/url\]/is', '/\[color=(.*?)\](.*?)\[\/color\]/is', '/\[yt\](.*?)\[\/yt\]/is', ); $replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<img src="$1" style="border:0">', '<a href="$1">$2</a>', '<font style="color:$1">$2</font>', '<object width="660" height="405"> <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"></embed> </object>', ); return nl2br(preg_replace($search,$replace,$input)); } There is an error on code: <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> and on: <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"> How can i use str_replace in this situation ? :S This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=317329.0 hi, i have the following which parses the quote tag and replaces it with a span $bb[] = "#\[quote\](.*?)\[/quote\]#si"; $html[] = "<span class='quote'>\\1</div>"; what i would like however is for the bbcode to be Quote from: xxxx where xxxx is the name of the person you are quoting. so how would i parse this? I also need the same for font color but if someone can provide a solution to this one then i think i could work it out. Code: [Select] [b][i][u] test test test test test test test test test test test test test test test. [/b][/i]/[u] If I need to cut the first five words, the bbcode closing tags will be remove. I'm trying to work on BBCode for a forum. Code: [Select] <?php $bb_Code = array( '[ code]' => '<code>', '[ /code]' => '</code>' ); foreach ($bb_Code as $value => $replace) { $text = str_replace($value, $replace, $text); } ?> Question is.. how would I get it so when I insert information into the database it gets cleaned (strip_tags, etc.) but doesn't disturb what is in the [ code ] tags? So basically it makes the html, etc. in the [ code ] tags just plain text? Thanks in advanced. Right now i used the following code to convert bbcode to html/php. i also need to incorporate QUOTE=name and URLS as well..how do i do that? Code: [Select] function bbcode_format ($str) { $str = htmlentities($str); $start = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[a\=(.*?)\](.*?)\[\/a\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[header\](.*?)\[\/header\]/is' ); $finish = array( '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', '<a href="$1">$2</a>', '<span style="color: $1">$2</span>', '<img src="$1" />', '<span class="h3">$1</span>' ); $str = preg_replace ($start, $finish, $str); return $str; } Code: [Select] $txt = preg_replace( "#\[yt\]http://www.youtube.com/watch?v=(.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Okay this is my code just for inserting it into HTML, the problem is whenever I try to use: Code: [Select] [yt]http://www.youtube.com/watch?v=l1G7TJD6Xu0[/yt] On my form to enter it does not work? But if I use Code: [Select] $txt = preg_replace( "#\[yt\](.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Code: [Select] [yt]l1G7TJD6Xu0[/yt] It works. But I want to use the full URL of the youtube, so I don't want my users to copy/paste just the "l1G7TJD6Xu0" Code , any help? Thank you This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=348145.0 Hi all, I've added bbcode to my forum on my website but I don't want users to be able to add javascript (or better put, I only want links to be http, https, ftp type links). How can I do this? Regards, Jason I have this function: function bbcode($input){ $input = strip_tags($input); $input = htmlentities($input); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url=http://(.*?)\](.*?)\[\/url\]/is', '/\[font color=(.*?) size=(.*?) face=(.*?)\](.*?)\[\/font\]/is', ); $replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<img src="$1">', '<a href="$1">$2</a>', '<font style="color:$1;font-size:$2;font-face:$3">$4</font>', ); return preg_replace($search,$replace,$input); } Now when i use this command($komentar is variable which is loaded from mysql): echo bbcode($komentar); it shows me this error: Warning: preg_replace() [function.preg-replace]: Unknown modifier '/' in /home/dotars/public_html/includes/functions.php on line 212 What is wrong here ? :S |