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. Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/ 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.... Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384251 Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Author Share Posted November 3, 2007 That tutorial doesn't work, apparently. Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384301 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] Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384303 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 >_> Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384313 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... Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384399 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. Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384423 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. Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384451 Share on other sites More sharing options...
LemonInflux Posted November 3, 2007 Author Share Posted November 3, 2007 What bit is regex, exactly? Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384466 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; } Link to comment https://forums.phpfreaks.com/topic/75912-parsing-help-bbcode/#findComment-384489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.