terungwa Posted May 15, 2014 Share Posted May 15, 2014 The bbcode below is not parsing code on multiple lines or recognizing line breaks, except the full content code is on one line. <?php function bbcode2html($var) { // code synthax highlighter $var = preg_replace('/\[code](.+?)\[\/code]/i', '<pre><code>$1</code></pre>', $var); return $var; } $content= '[code] <!DOCTYPE html> [/code]'; echo $content= bbcode2html($content); ?> I attempted introducing a new line recognition character into the regex as shown below, but its not working. <?php function bbcode2html($var) { // code synthax highlighter $var = preg_replace('/\[code]\r\n(.+?)\[\/code]/i', '<pre><code>$1</code></pre>', $var); return $var; } $content= '[code] <!DOCTYPE html> [/code]'; echo $content= bbcode2html($content); ?> I would appreciate your suggestions. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/288510-bbcode-code-tag-is-not-parsing-multiple-lines/ Share on other sites More sharing options...
Solution Ch0cu3r Posted May 15, 2014 Solution Share Posted May 15, 2014 Apply the s pattern modifier to your regex Quote Link to comment https://forums.phpfreaks.com/topic/288510-bbcode-code-tag-is-not-parsing-multiple-lines/#findComment-1479554 Share on other sites More sharing options...
terungwa Posted May 16, 2014 Author Share Posted May 16, 2014 Thanks Ch0cu3r. Quote Link to comment https://forums.phpfreaks.com/topic/288510-bbcode-code-tag-is-not-parsing-multiple-lines/#findComment-1479702 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.