immanuelx2 Posted May 22, 2009 Share Posted May 22, 2009 Hey all. I have been trying to figure this out for literally several hours and my head is starting to hurt. I come to you experts as a last resort. I am by no means a regexp expert, in fact the format below is something I snagged off the internet, so it may be wrong... So far I have this for my bbcode parsing: <?php $bbcode = array( '@\[url=(.*?)\](.*?)\[/url\]@si' => '<a href="\\1" target="_blank">\\2</a>', '@\[quote\](.*?)\[/quote\]@si' => '<i>"\\1"</i>', '@\[ul\](.*?)\[/ul\]@si' => '<ul>\\1</ul>' , '@\[li\](.*?)\[/li\]@si' => '<li>\\1</li>' ); return preg_replace(array_keys($bbcode), array_values($bbcode), $string); ?> However, when it comes to the "ul" and "li" tags... I want to omit any newline ("\n") characters before or after those elements, because I have a nl2br() statement that parses right at the end to output the HTML, and since <li> tags are naturally list-type elements, they don't need extra <br /> around them. Just like in these forums: [list] [*]item 1 [*]item 2 [/list] between items 1 and 2, and the two list tags, no additional line breaks are added, even though there are newlines created when that code is written. So my question is, how can I remove the newlines at those specific points only, so that my nl2br() can parse the rest of the newlines in my string as breaks? Thanks in advance for any help Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 22, 2009 Share Posted May 22, 2009 You can use \s And m modifier for multiple lines. Quote Link to comment Share on other sites More sharing options...
immanuelx2 Posted May 22, 2009 Author Share Posted May 22, 2009 You can use \s And m modifier for multiple lines. Could you elaborate? Sorry I'm a newb when it comes to regexp... Could you maybe give me an example of what you mean? Quote Link to comment Share on other sites More sharing options...
immanuelx2 Posted May 23, 2009 Author Share Posted May 23, 2009 bump Quote Link to comment Share on other sites More sharing options...
immanuelx2 Posted May 26, 2009 Author Share Posted May 26, 2009 anyone? 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.