I changed "$code_treated" to "$post_abridged", because I hadn't defined the "$code_treated" variable at missing the "code" part.
So if you find that the script returns a blank page, make sure you haven't missed any step; and if you have, change the variable name.
[Sorry about my bad English: I'm Spanish and I'm not very confident with it]
Posted by AdRock on September 09st 2007 (07:12)
I have worked out why it wouldn't work before by following the article again but I still can't output what is entered in the form. All I get is a blank page

|
Posted by AdRock on August 08th 2007 (21:12)
I have got the form with the BBcode working fine now after reading the article properly but I am now stuck on converting teh BBcode into HTML.
First thing...is the file supposed to be called bbcode.php like referred to in the first part of the article?
Second thing....is there a complete listing of the bbcode.php? I have gone through the second part and put the code together but when i try and preview what I have done...it just echoes this
| QUOTE | function output_post ($post) { //Make safe any html $post_no_html = htmlspecialchars($post); //Make sure there is no whitespace at the end of the message //It's conceivable that the user will start their message with whitespace $post_abridged = chop($post_no_html); //Callback function for preg_replace_callback below function convert_for_html ($matches) { $regex[0] = "["; $regex[1] = "]"; $replace[0] = "["; $replace[1] = "]"; ksort($regex); ksort($replace); $treated = str_replace($regex, $replace, $matches[1]); $output = 'Code: ' . $treated . ' '; return $output; } //Convert code tags $code_treated = preg_replace_callback( "/\[code\](.+?)\[\/code\]/s", "convert_for_html", $post_abridged); //Arrays for the bbCode replacements $bbcode_regex = array(0 => '/\[b\](.+?)\[\/b\]/s', 1 => '/\[i\](.+?)\[\/i\]/s', 2 => '/\[u\](.+?)\[\/u\]/s', 3 => '/\[quote\](.+?)\[\/quote\]/s', 4 => '/\[quote\=(.+?)](.+?)\[\/quote\]/s', 5 => '/\[url\](.+?)\[\/url\]/s', 6 => '/\[url\=(.+?)\](.+?)\[\/url\]/s', 7 => '/\[img\](.+?)\[\/img\]/s', 8 => '/\[color\=(.+?)\](.+?)\[\/color\]/s', 9 => '/\[size\=(.+?)\](.+?)\[\/size\]/s'); $bbcode_replace = array(0 => '$1', 1 => '$1', 2 => '$1', 3 => 'Quote: $1 ', 4 => '$1 said: $2 ', 5 => '$1', 6 => '$2', 7 => '', 8 => '$2', 9 => '$2'); ksort($bbcode_regex); ksort($bbcode_replace); //preg_replace to convert all remaining bbCode tags $post_bbcode_treated = preg_replace($bbcode_regex, $bbcode_replace, $code_treated); //Convert new lines to $post_with_br = nl2br($post_bbcode_treated); echo $post_with_br; }; |
|