Jump to content

Help with accepting newlines in simple pattern


nhpr

Recommended Posts

I'm (trying) to write my own custom forum software.  It allows users to input code for their pages using BB code for styling.  So the following code:

 

[b]Hello
This should work[/b]

 

would display on the actual page as:

"Hello

This should work"

 

However, my regular expression can't handle new lines, and, try as I might, I can't get it to work.  I've tried various ways of sticking \s into the expression, but I'm obviously lacking some sort of important concept.

 

The following is the code to parse the page's code:

 

$rexp = "#(\[b\])(.*)(\[[/\\\\]b\])#e";
$input = preg_replace($rexp, "('<b>$2</b>')", $input);

 

Can anyone tell me how to edit the (.*) statement in the middle to accept newline characters in the user's text?

I know I need the \s modifier, but I need help with the syntax itself (hence the bit above about how I've tried sticking \s virtually everywhere in that string).  The PHP documentation seems to assume that I should just know how to use these magical modifiers and gives no examples.

 

Any suggestions on how to alter my $rexp string above or documentation on how to properly apply modifiers would be greatly appreciated.  I just started with regular expressions yesterday and was only barely capable of coming up with what I have above, so I apologize that I essentially need to be led by the hand to an answer.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.