Jump to content

Parsing Help (BBCode)


LemonInflux

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.