Home | Forums | Articles | F@H
Help | Search | Members | Calendar | Forum Map | Cybervillage | Archive
Welcome Guest ( Log In | Register | Resend Validation Email )


>  IceTeks Forums -> Technology -> IceTeks Articles


  Reply to this topicStart new topic

>  Regular expressions and all things nice
Track this topic | Email this topic | Print this topic
Red Squirrel
Posted: Apr 23 2005, 01:59 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



This is the second article looking at how to allow your visitors to post content using bbCode. While the previous article looked at the client-side processing this article will deal with how to treat bbCode formatted text once it reaches your server.

http://www.iceteks.com/articles.php/javascript2/1


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Streety
Posted: Jul 5 2005, 04:03 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 185
Member No.: 475
Joined: 16-August 04
Ice Cubes: 5



Thanks for taking the time to read the article kryptx. You're absolutely right. I maintain linebreaks in the cascade stylesheet by setting whitespace as pre:

CODE
.code_box {font-weight:normal;
 font-family: Courier;
 white-space:pre;
 background-color:#00FFFF;
 border-style: solid;
 border-width: 1px;
 border-color: #959595;
 text-indent: 0px;
}


I also apply the nl2br function to the whole post which adds extra line breaks into the code tags.

The best way of dealing with it is probably just deleting whitespace:pre from the stylesheet. Thanks for picking up on the error! smile.gif

hi tayfun, I can't say I've ever seen that error before. I thought at first you may have copied the function into your script twice but on testing this I don't get an error.

You could try using function_exists and before declaring the function and see what it comes back with. Not much else I can suggest I'm afraid.


--------------------
user posted image
PMEmail Poster Top
Red Squirrel
Posted: Oct 15 2005, 12:40 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



Yeah but trying to do anything strictly xhtml compliant is nearly impossible and has no benifits, usually just sticking to W3C html 5.02 (or whatever that number is:P) should almost guarantee cross browser compatability. Unless you want a really crappy site <u> <b> <i> are rather useful. You can always use css but then that increases the file size.

ex: <font style="font-weight:bold">hi</font>

vs

<b>hi</b>

Even with a class it's longer:

<font class="b">hi</font>

Though it would be possible to get bbcode to produce this, but it would only increase the file size of the DB.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
Red Squirrel
Posted: Oct 16 2005, 01:29 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



Yes Xhtml is great if you can be diciplined to actually code that strictly, but in my opinion it's too much, just plain normal W3C is good enough for me. em320.gif


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
MikeDB
Posted: Oct 16 2005, 04:04 PM
Quote Post

Use the teeth!

Group Icon

Group: Ice Age Members
Posts: 1 248
Member No.: 874
Joined: 13-May 05
Ice Cubes: 95



Yes yes I dont nkow why im even answering to this post but... Yes.


--------------------
PMEmail PosterUsers WebsiteMSN Top
Red Squirrel
Posted: Oct 18 2005, 08:30 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



Hey sorry to the person who just posted and got hit with the spam bot. really not sure why it snapped. Must be the word compliant, thats often in spam.

Feel free to register as the spam bot validation wears off after some posts.


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
AdRock
Posted: Aug 30 2007, 09:12 PM
Quote Post

Unregistered











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; };


How do i get this working?
Top
AdRock
Posted: Sep 1 2007, 07:12 AM
Quote Post

Unregistered











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
Top
unokpasabaxaki
Posted: Mar 24 2008, 08:44 PM
Quote Post

Unregistered











I also had a "blank page" problem, but I've resolved it.
When I saw the function returned an empty string, I checked the code, and after copying outside of the function, I found out that it failed because I had missed the "code" part. I had:
CODE
$post_abridged = chop($post_no_html);
$bbcode_regex = [...]
$post_bbcode_treated = preg_replace($bbcode_regex, $bbcode_replace, $code_treated);

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]
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | IceTeks Articles | Next Newest »

Topic Options Reply to this topicStart new topic

 



[ Script Execution time: 0.0364 ]   [ 13 queries used ]   [ GZIP Enabled ]

< Home | Forums | Contact >