cujo Posted July 11, 2007 Share Posted July 11, 2007 I have an issue with replacing BBCode with html. I found a script that does all the conversions for me, but one thing it leaves out is superscripts and subscripts. I thought I'd simply modify the bold code: $Text = preg_replace("(\[b\](.+?)\[\/b])is",'<span class="bold">$1</span>',$Text); With the superscript and subscript code: $Text = preg_replace("(\[sub\](.+?)\[\/sub])is",'<sub>$1</sub>',$Text); $Text = preg_replace("(\[sup\](.+?)\[\/sup])is",'<sup>$1</sup>',$Text); But that didn't work. I found some articles on regex, but they were pretty vague. I was hoping someone could help me out. Quote Link to comment Share on other sites More sharing options...
cujo Posted July 11, 2007 Author Share Posted July 11, 2007 I would also like to know how to do it for Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 11, 2007 Share Posted July 11, 2007 <?php $Text = "[b]this is bold[/b] This has a superscript[sup]3[/sup]. This has a subscript[sub]1[/sub]\n"; echo $Text; $Text = preg_replace( array( '|\[b\](.+?)\[/b\]|is', '|\[sup\](.+?)\[/sup\]|is', '|\[sub\](.+?)\[/sub\]|is' ),array( '<span class="bold">$1</span>', '<sup>$1</sup>', '<sub>$1</sub>' ),$Text ); echo $Text; ?> OUTPUT: [b]this is bold[/b] This has a superscript[sup]3[/sup]. This has a subscript[sub]1[/sub] <span class="bold">this is bold</span> This has a superscript<sup>3</sup>. This has a subscript<sub>1</sub> Quote Link to comment Share on other sites More sharing options...
cujo Posted July 11, 2007 Author Share Posted July 11, 2007 It doesn't work. Bold works, but subscript and superscript does not. I can't get center to work either. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 11, 2007 Share Posted July 11, 2007 It works fine for me. You've got something else wrong. Quote Link to comment Share on other sites More sharing options...
cujo Posted July 11, 2007 Author Share Posted July 11, 2007 It's always something glaringly obvious, isn't it? Thanks for your help, Wildbug, I figured out what I was doing wrong. 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.