Jump to content

Recommended Posts

Posted

I was wondering how do forums like phpbb and others do regular expressions across several lines instead of line per line...

 

Example, I have bbcode-like regular expressions on my scripts yet they will only work if they are on the same line as they should since these test line per line. But on forums like phpbb and others, I am able to do something like this

 

>[b]

test

[/b]

 

and it parses just fine.

 

Does anyone know how they do something like this.

  • 2 weeks later...
Posted

No bumping allowed. Please read the Forum Guidelines. All posts are seen, it is rare that one gets overlooked. While we try and answer every post with at least an "I see the post but am not sure" response we dont get them all.

 

No answer was given due to the fact that those 38 that have seen the post cannot provide anything as a solution.

Posted

OK, that is strange. I see your post and then the bump. I come back today and there is Rauls and your post above mine. Strange. In any event, no bumping and good luck on looking through all that code.

Posted

Hi,

I also needed bbCode support on one of my sites a while ago. I found the part of the phpbb code that took care of the text parsing but I was to lazy to figure out how those regular expressions work :dance: .

 

I wrote my own function that does some search and replace actions instead, it might be a little slower but it seems to work :unsure:.

 

The functions supports:

[ i ] italic [ /i ]

[ b ] bold [ /b]

[ u ] underline [ /u ]

[ url ] links [ /u ]

[ url=http://something ] hyperlinks [ /url ]

[ img ] image.gif [ /img ]

 

I attached it to this post.

 

Hope it helps :unsure:

textparsing.txt

  • 4 weeks later...
Posted

oh i totally forgot about this...it didn't take a few hours like i thought..more like 2 minutes...just looked at the bbcode.php file in the includes directory.

 

Just letting u guys know that the way to do regexp across several lines is by using the s modifier.

 

http://us2.php.net/manual/en/reference.pcr...n.modifiers.php

s (PCRE_DOTALL)

 

    If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a]always matches a newline character, independent of the setting of this modifier.

 

 

Its that simple...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...