web-itec, on 09 January 2012 - 04:11 PM, said:
Hello, So on my CMS ive got a bb code so the client can change font colour and size etc
the function works like this
client clicks color red so, it will appear
[color=red]text[/color]
to them but when it gets displayed on their site it will change
[color=red]
to
<span style="color:red;">
etc
thats a problem because, if there is a size set on the text already on the css then it wont work because its then inside the span aswel, so then the client does
[color=red][size=12px]text[/size][/color]
so when outputted it will be
<span style="color:red;"><span style="font-size:12px;">text</span></span>
in the html
and obviously because the text is in another span then the colour wont be shown only the font will
how can i fix this?
Any help would be appreciated
Gary
idk if this will help but heres a class i wrote to parse bbcode for my blog software odviously some of it u wont need such as the adsense bit but you can change it as needed
class bbcode{
private $search;
private $replace;
/**
* bbcode::parse()
*
* @param mixed $string
* @return void
*/
public function parse($string){
global $post,$page,$adsense_enabled_in_post;
/**
*Adsence unit
*/
if($page || $post && $adsense_enabled_in_post === true){
global $width_of_unit,$height_of_unit,$publisher_id,$ad_slot_id;
$adsense = '
<span class="adUnit"><script type="text/javascript"><!--
google_ad_client = "'.$publisher_id.'";
google_ad_slot = "'.$ad_slot_id.'";
google_ad_width = '.$width_of_unit.';
google_ad_height = '.$height_of_unit.';
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span>
';
}else{
$adsense = '';
}
/**
*Replace everything except our you tube code
**/
$string = str_replace('http://www.youtube.com/watch?v=','',$string);
/**Search**/
$this->search = array(
'/\[bold\](.*?)\[\/bold\]/is',
'/\[italic\](.*?)\[\/italic\]/is',
'/\[h1\](.*?)\[\/h1\]/is',
'/\[h2\](.*?)\[\/h2\]/is',
'/\[h3\](.*?)\[\/h3\]/is',
'/\[h4\](.*?)\[\/h4\]/is',
'/\[h5\](.*?)\[\/h5\]/is',
'/\[h6\](.*?)\[\/h6\]/is',
'/\[center\](.*?)\[\/center\]/is',
'/\[right\](.*?)\[\/right\]/is',
'/\[left\](.*?)\[\/left\]/is',
'/\[allcaps\](.*?)\[\/allcaps\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[color fcolor=(.*?)\](.*?)\[\/color\]/is',
'/\[url=(.*?)\](.*?)\[\/url\]/is',
'/\[image\](.*?)\[\/image\]/is',
'/\[youtube\](.*?)\[\/youtube\]/is',
'/\[adsense\]/',
'/\[code\](.*?)\[\/code\]/is',
'/:\)/',
'/:\(/',
'/\:p/',
'/\:wink/',
'/\:unsure/',
'/\:roll/',
'/\:o/',
'/\:mellow/',
'/\:mad/',
'/\:laugh/',
'/\:huh/',
'/\:blink/',
'/\:cool/',
'/\:shy/',
'/\:sick/',
'/\:sweat/',
'/\:stamp/',
'/\:tears/',
'/\:bleh/',
'/\:bop/',
'/\:bouncy/',
'/\:chin/',
'/\:chap/',
'/\:biggrin/',
'/\:angel/',
'/\:bye/',
'/\:drool/',
'/\:dirol/',
'/\:hi/',
'/\:good/',
'/\:flm/',
'/\:plea/',
'/\:santa_cool/',
'/\:santa_grin/',
'/\:santa_smiley/',
'/\:rudolph/'
);
/**Replace**/
$this->replace = array(
'<b>$1</b>',
'<i>$1</i>',
'</p><h1>$1</h1><p>',
'</p><h2>$1</h2><p>',
'</p><h3>$1</h3><p>',
'</p><h4>$1</h4><p>',
'</p><h5>$1</h5><p>',
'</p><h6>$1</h6><p>',
'<span style="text-align:center; display:block;">$1</span>',
'<span style="text-align:right; display:block;">$1</span>',
'<span style="text-align:left; display:block;">$1</span>',
'<span style="text-transform:uppercase;">$1</span>',
'<u>$1</u>',
'<span style="color:$1;">$2</span>',
'<a href="$1">$2</a>',
'<img src="$1" alt="" onmouseover="image_hover_expand(this)" onmouseout="image_hover_collapse(this)" width="220" height="220" />',
'<iframe width="300" height="300" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',
'
'.$adsense.'
',
'</p><div class="code"><code><span class="code_snipplet_head">Code Snipplet</span><br />$1</code></div><p>',
'<img src="smilies/smile.gif" alt="" />',
'<img src="smilies/sad.gif" alt="" />',
'<img src="smilies/tongue.gif" alt="" />',
'<img src="smilies/wink.gif" alt="" />',
'<img src="smilies/unsure.gif" alt="" />',
'<img src="smilies/rolleyes.gif" alt="" />',
'<img src="smilies/ohmy.gif" alt="" />',
'<img src="smilies/mellow.gif" alt="" />',
'<img src="smilies/mad.gif" alt="" />',
'<img src="smilies/laugh.gif" alt="" />',
'<img src="smilies/huh.gif" alt="" />',
'<img src="smilies/blink.gif" alt="" />',
'<img src="smilies/cool.gif" alt="" />',
'<img src="smilies/shy.gif" alt="" />',
'<img src="smilies/sick.gif" alt="" />',
'<img src="smilies/sweat.gif" alt="" />',
'<img src="smilies/stamp.gif" alt="" />',
'<img src="smilies/tears.gif" alt="" />',
'<img src="smilies/bleh.gif" alt="" />',
'<img src="smilies/bop.gif" alt="" />',
'<img src="smilies/bouncy.gif" alt="" />',
'<img src="smilies/chin.gif" alt="" />',
'<img src="smilies/chap.gif" alt="" />',
'<img src="smilies/biggrin.gif" alt="" />',
'<img src="smilies/angel.gif" alt="" />',
'<img src="smilies/bye.gif" alt="" />',
'<img src="smilies/drool.gif" alt="" />',
'<img src="smilies/dirol.gif" alt="" />',
'<img src="smilies/hi.gif" alt="" />',
'<img src="smilies/good.gif" alt="" />',
'<img src="smilies/flm.gif" alt="" />',
'<img src="smilies/plea.gif" alt="" />',
'<img src="smilies/santa_cool.gif" alt="" />',
'<img src="smilies/santa_grin.gif" alt="" />',
'<img src="smilies/santa_smiley.gif" alt="" />',
'<img src="smilies/rudolph.gif" alt="" />'
);
return preg_replace($this->search,$this->replace,$string);
}
}
$bbcode = new bbcode;