sanguina
(Bha100710)
February 14, 2013, 5:57pm
1
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
seenivasan
(Chellamnivas)
February 14, 2013, 6:32pm
2
Dear Friend
Would you please try this?
echo CHtml::decode($model->content);
Regards.
outrage
(Site Sense Web)
February 14, 2013, 11:06pm
3
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.
sanguina
(Bha100710)
February 15, 2013, 4:45am
4
@seenivasan - thanks worked great
outrage:
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.
@outrage - thanks for replying