nhpr Posted August 4, 2010 Share Posted August 4, 2010 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? Quote Link to comment Share on other sites More sharing options...
cags Posted August 4, 2010 Share Posted August 4, 2010 The . capture all special character doesn't match newline characters unless you specify the s modifier. Quote Link to comment Share on other sites More sharing options...
nhpr Posted August 4, 2010 Author Share Posted August 4, 2010 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. Quote Link to comment Share on other sites More sharing options...
cags Posted August 4, 2010 Share Posted August 4, 2010 Several of the user submitted comments on that page demonstrate the use, clicking through a few pages will give other examples, you are already using the e modifier. Quote Link to comment Share on other sites More sharing options...
nhpr Posted August 4, 2010 Author Share Posted August 4, 2010 I was doing it properly in my experiments, but a bug in another section of the code was throwing me off. Thanks for the help. Now how do I set the thread as SOLVED? Quote Link to comment Share on other sites More sharing options...
cags Posted August 5, 2010 Share Posted August 5, 2010 There's a green button in the bottom left of threads you started, labelled 'Mark Solved'. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.