LemonInflux Posted November 3, 2007 Share Posted November 3, 2007 Firstly, I've looked around a bit, and I've found half the solution. I'm trying to make a BBCode parser for a forum project I'm working on. I've got the whole bit that finds the code and says turn [b] -> <strong> and that, but my problem is, if you put [b]text , the rest of the page is in bold. What I want is it to automatically add the closing tag. How do I do this? NOTE: used because it was messing up the post. Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 3, 2007 Share Posted November 3, 2007 Check this tutorial out: http://www.phpfreaks.com/tutorials/141/0.php You should check for pairs of [ b][ /b] tags instead of look for one and add the other.... Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Author Share Posted November 3, 2007 That tutorial doesn't work, apparently. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Author Share Posted November 3, 2007 I turn on parse BBCode and Smileys, and [b]text[/b] supposedly makes [Posted ImagePosted ImagePosted ImagedPosted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted ImagedPosted ImagePosted ImagePosted ImagedPosted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted ImagedPosted ImagePosted ImagePosted ImagedPosted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev style='text-alPosted Imagen: rPosted Imageht;'>Posted Imagev>>b] Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Author Share Posted November 3, 2007 Hm. That last post actually broke firefox. I can't view this page in firefox. So now I have to go back to IE >_> Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 3, 2007 Share Posted November 3, 2007 I'm viewing it fine in FF. Regarding the "I turn on parse BBCode and Smileys, and:" you should know why it does so, you wrote the code. I don't know if the tutorial presents code ready to use or if you have to fill in some gabs your self... Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Author Share Posted November 3, 2007 I didn't write it. That's the 'to test the code:' bit of the tutorial you linked me to. Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 3, 2007 Share Posted November 3, 2007 Oh, that has always been acting weird. Read the tutorial and get the idea of how regex is used to find matching pairs of open and close tags and replace them. Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Author Share Posted November 3, 2007 What bit is regex, exactly? Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 3, 2007 Share Posted November 3, 2007 The regex'es of the tutorial? function _parse_bbcodes($data) { $data = preg_replace("`[(b|i|u|url|mail|img|center|right)][/(b|i|u|url|mail|img|center|right)]`",'',$data); $data = preg_replace("`[url](.*)[/url]`sUi","<a href='\1'>\1</a>",$data); $data = preg_replace("`[url=(.*)](.*)[/url]`sUi","<a href='\1'>\2</a>",$data); $data = preg_replace("`[mail](.*)[/mail]`sUi","<a href='mailto:\1'>\1</a>",$data); $data = preg_replace("`[mail=(.*)](.*)[/mail]`sUi","<a href='mailto:\1'>\2</a>",$data); $data = preg_replace("`[b](.*)[/b]`sUi","<span style='font-weight: bold;'>\1</span>",$data); $data = preg_replace("`[i](.*)[/i]`sUi","<span style='font-style: italic;'>\1</span>",$data); $data = preg_replace("`[u](.*)[/u]`sUi","<span style='text-decoration: underline;'>\1</span>",$data); $data = preg_replace("` [center](.*)[/center] `sUi","<div style='text-align: center;'>\1</div>",$data); $data = preg_replace("` [right](.*)[/right] `sUi","<div style='text-align: right;'>\1</div>",$data); $data = preg_replace("`[img=(.*)]`sUi","<img src='\1' alt='Posted Image' style='border: 0px;' />",$data); return $data; } 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.