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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.