Parsing Html In Yii

Hello

I am storing content in mysql with html markup.

When i get it via the model and output it to the view file like




echo $model->content; 



it renders the output with the html markup.

How do i parse html to show only the content in the view ?

thank you for your reply :)

Dear Friend

Would you please try this?




echo CHtml::decode($model->content);



Regards.

If you want just the text as output, use strip_tags($content).

You might find that line breaks are missing, causing the text to look confusing.

If you’re lucky your can use ln2br($content).

If there were no line breaks in the html, you will have to make a function to use before strip_tags and ln2br, that searches for the end tags of elements such as </h1> to </h6>, </p>, </li>, </ul> etc…

Just use str_replace or something to replace those tags with the same tag + "\n", like this:


$content = str_replace("</p>", "</p>\n", $content);

...


$content = strip_tags($content);

$content = ln2br($content);

If you display the text in a textarea, you can omit ln2br.

@seenivasan - thanks worked great :)

@outrage - thanks for replying :)