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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

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.