tinker Posted December 26, 2007 Share Posted December 26, 2007 Hi, i'm just tinkering with a wysiwyg editor. I've just finished the JS side and thought the php would be easier, however it's not handling the way I expected it to! Basically say there's multiple bold tags within a given text, then it takes just the first and very last, not each and every set. function phpbbcode_convert($s) { $sret = ""; $pattern = array('/\\n/im', '/\[b\](.*)\[\/b\]/im', '/\[i\](.*)\[\/i\]/im', '/\[u\](.*)\[\/u\]/im', '/\[h1\](.*)\[\/h1\]/im' ); $replacement = array('<br>', '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<h1>$1</h1>' ); $sret = preg_replace($pattern, $replacement, $s); return $sret; } and let's say I call it with this... $test = "[b]Hello[/b] [i]this[/i] [u]is a[/u] [b]test[/b] [h1]mytitle[/h1] [H1]mytitle[/H1] [b]test[/b] [b]test[/b]"; print "POST: <br>".phpbbcode_convert($test)."<br>"; When using JS I use the pattern modifiers 'ig'. Any help appreciated! P.S. I can accomplish these in a simpler manner, however the simpler way won't be any good for the more complex variations needed later... Quote Link to comment https://forums.phpfreaks.com/topic/83279-bbcode-regex/ Share on other sites More sharing options...
Daleeburg Posted December 26, 2007 Share Posted December 26, 2007 I havent checked this, but if you exchange the single quotes in the arrays with double quotes, will it work? it has to do with how php sees ' and " ~D Quote Link to comment https://forums.phpfreaks.com/topic/83279-bbcode-regex/#findComment-423661 Share on other sites More sharing options...
tinker Posted December 26, 2007 Author Share Posted December 26, 2007 Sounded like a good solution, but sadly no ball! Quote Link to comment https://forums.phpfreaks.com/topic/83279-bbcode-regex/#findComment-423667 Share on other sites More sharing options...
Daleeburg Posted December 26, 2007 Share Posted December 26, 2007 It was just a guess, sorry. ~D Quote Link to comment https://forums.phpfreaks.com/topic/83279-bbcode-regex/#findComment-423671 Share on other sites More sharing options...
anon Posted December 26, 2007 Share Posted December 26, 2007 Not trying to be irritating, but shouldn't this be in the regex section? I understand that you probably get more exposure in here, but still. Quote Link to comment https://forums.phpfreaks.com/topic/83279-bbcode-regex/#findComment-423672 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.