Php Reg Exp Across Several Lines

liunx

Guest
I was wondering how do forums like phpbb and others do regular expressions across several lines instead of line per line...<br /><br />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 <br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br /><br />test<br /><br /><!--c2--></div><!--ec2--><br /><br />and it parses just fine. <br /><br />Does anyone know how they do something like this.<!--content-->
bump <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /><!--content-->
Have you tried looking at phpBB's source code? <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><!--content-->
<!--QuoteBegin-TCH-Raul+Sep 26 2004, 05:38 AM--><div class='quotetop'>QUOTE(TCH-Raul @ Sep 26 2004, 05:38 AM)</div><div class='quotemain'><!--QuoteEBegin-->Have you tried looking at phpBB's source code? <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><!--QuoteEnd--></div><!--QuoteEEnd--><br /> hehe...I figure that would take a few hours.... I'll start tomorrow i guess.<!--content-->
No bumping allowed. Please read the <a href="http://http://www.totalchoicehosting.com/forums/index.php?act=boardrules" target="_blank">Forum Guidelines</a>. 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.<br /><br />No answer was given due to the fact that those 38 that have seen the post cannot provide anything as a solution.<!--content-->
yikes...sorry about that.<!--content-->
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.<!--content-->
Hi,<br />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 <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> .<br /><br />I wrote my own function that does some search and replace actions instead, it might be a little slower but it seems to work <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />.<br /><br />The functions supports:<br />[ i ] italic [ /i ]<br />[ b ] bold [ /b]<br />[ u ] underline [ /u ]<br />[ url ] links [ /u ]<br />[ url=http://something ] hyperlinks [ /url ]<br />[ img ] image.gif [ /img ]<br /><br />I attached it to this post.<br /><br />Hope it helps <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
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. <br /><br />Just letting u guys know that the way to do regexp across several lines is by using the <b>s</b> modifier. <br /><br /><a href="http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php" target="_blank">http://us2.php.net/manual/en/reference.pcr...n.modifiers.php</a><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->s (PCRE_DOTALL)<br /><br />    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.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br /><br />Its that simple...<!--content-->
Thanks, section31. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br />Glad you figured it out Thumbs Up<!--content-->
 
Top