Home   -   News   -   Game Tour   -   Screenshots   -   Rules   -   Chat   -   Contact   -   Forum
pt ro hu de es
pl it no nl en
The Land of Destiny Hero welcomes you.
Role playing game or called MMORPG free browser game
Posts

Breadcrumbs to navigate the website Homepage / Forum / Personal projects / bbcode



Topic: bbcode Post reply

Page: 1 [2] [3] [4]

Moderator Posted on: 22-06-2008 16:39:58
Posts: 543



to fire off this forum I'd like to ask how you do your BBcode without having linebreaks on places where they should not be (like I have now with my url tags
Member Posted on: 22-06-2008 16:43:51
Posts: 822



Give us a sample of your code.
Moderator Posted on: 22-06-2008 16:46:53
Posts: 543



well I'm not really having a good sample but this is how I used to do it.

-have a table in database with columns (bbcode,html)
-then use preg_replace() to replace bb with html.

but with the url tags I get a linebreak in the href='' part of the link and my browser does not like that, so it gives a half link.
Developer Posted on: 22-06-2008 17:01:20
Posts: 3379



already checked code from other ppl?

http://oisyn.nl/articles.php/12
Moderator Posted on: 22-06-2008 18:44:34
Posts: 543



hmm. that looks pretty difficult

Actually what I need is this.

I have to get the input text without linebreaks.
Then replace all the bbcode.
Then add linebreaks where needed without touching the html tags.
Member Posted on: 22-06-2008 20:39:33
Posts: 822



I don't see the problem with them linebreaks.
What about
<?php
$bbcode = preg_replace("/\[u\](.*?)\[\/u\]/si", "<u>\\1</u>", $bbcode);
??
Moderator Posted on: 22-06-2008 21:11:08
Posts: 543



no it's not the problem with <u> tags but with <a href=''> tags.

when you convert the bbcode to html and you accedently have a linebreak in the href='' part, your link gets messed up.
<?php
$text = preg_replace("/\[url\](.*)\[\/url\]/","<a href='$1">$1</a>","http://dit.is.\neen.link.nl");

gives: http://dit.is.
een.link.nl'>http://dit.is.
een.link.nl

but I already solved it with a text parser which adds linebreaks to the text but leaves html tags untouched.

btw what does the 'si' mean after the regex pattern?
Member Posted on: 22-06-2008 21:25:09
Posts: 822



Those are so called "modifiers".
i means case-insensitive
s means newlines are included in the match, which may be able to solve your problem as well.
Moderator Posted on: 23-06-2008 17:18:02
Posts: 543



a little question:

why do u use (.*?) instead of (.*) because * already checks for 0 or more instances of the previous character?

? checks for 0 or 1 instance. you don't need it if u use * or do you?
Member Posted on: 23-06-2008 17:22:03
Posts: 822



Don't know exactly. See what happens with
"[u][/u]"
with both
(.*)
and
(.*?)

Page: 1 [2] [3] [4]

You have to register or login first before you are able to reply.
LoD is a free online rts game free online MMORPG