convert bbcode text to html

I tried using Class CMarkdownParser to convert text bbcode to Html text like :




'[b]BB Code[/b]'  =====convert====>  '<b>BB Code</b>'




the code in class model:





protected function beforeValidate()

{


    if(!empty($this->content_text))

    {

        $purifier=new CHtmlPurifier();

        $parser=new CMarkdownParser();

        $this->content_text=$parser->transform($this->content_text);

        $this->content_html = $purifier->purify($this->content_text);

    }

}




and code in view in CDetailView:




<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'title',

    array(

           'name' => 'categorie_id',

            'value' => Categorie::Model()->FindByPk($model->categorie_id)->name,

        ),

		

    array(

    'name'=>'content_html',

    'type'=>'raw',

    'value'=>$model->content_html,

        ),

    


)); ?>




but it dosent currectly:




'[b]BB Code[/b]'  =====converted====>  <p>[b]BB Code[/b]</p>



While I expect to be below convert and BBcode tag be removed:




'[b]BB Code[/b]'  =====convert====>  <b>BB Code</b>



I’ve spent too much time to solve this problem and the tools used by yiidecoda, I got an error.

And given that I am a beginner. I’m grateful you explain with an example. :D

I’m very glad of your help. :)

I think you’ll be happier with this.

I’m very grateful, but also a question whether it also provides security? Html text may validate whether the CHtmlPurifier class is sufficient.

Unless you’re doing something extremely fancy where you’ll have to take care of entity masking yourself, I’d say it’s safe, yes. Shouldn’t stop you from running CHtmlPurifier if it makes you feel better ;)