Jump to content

[font] bb code


Porl123

Recommended Posts

I've been trying to create a bb code for my site which would allow the attributes color, size and face, but and can't really think of any way it would work. Most of my regex is guesswork so I'm struggling with this a bit.

The tag wouldn't strictly need any attributes and could be in any particular order, so it would be a lot like the html <font> tag.

 

If anyone could point me in the right direction I'd appreciate it. here's what I have so far:

 

$string = preg_replace('/\[font([\sface|\ssize|\scolor\]=](.+?)(\]|\s)+)/i','',$string);

 

The bit where I've stumbled is the second parameter. I'm not really where I'd go from there. Anyway, if you can help me, cheers!

Link to comment
Share on other sites

I have it almost exactly how I want it, but I need to change something.

 

$string = preg_replace('/\[font((\scolor|\ssize|\sface)=\"(.+?)\")\]/i','<font\\1>',$string);

 

In most respects, this works, although font size doesn't work in some browsers so I think I'll have to somehow replace it for its CSS equivalent. Does anyone know I can do this? Cheers

Link to comment
Share on other sites

I have a bb code setup and did it like this:

 

$simple_search = array(    
                '/\[font\=(.*?)\](.*?)\[\/font\]/is',  
                '/\[size\=(.*?)\](.*?)\[\/size\]/is',  
                '/\[color\=(.*?)\](.*?)\[\/color\]/is', 
                );  

$simple_replace = array(    
                '<span style="font-family: $1;">$2</span>',  
                '<span style="font-size: $1;">$2</span>',  
                '<span style="color: $1;">$2</span>',  
                );  

$text = preg_replace ($simple_search, $simple_replace, $text);

 

 

Hope this helps  ;)

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.