Yii Framework Forum: Parsing Html In Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Parsing Html In Yii Rate Topic: -----

#1 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 14 February 2013 - 12:57 PM

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 :)
until I become certain that there is no certainty.
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 14 February 2013 - 01:32 PM

Dear Friend

Would you please try this?

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


Regards.
0

#3 User is offline   outrage 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 312
  • Joined: 10-November 09
  • Location:Blackpool, United Kingdom

Posted 14 February 2013 - 06:06 PM

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.
0

#4 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 14 February 2013 - 11:45 PM

seenivasan said:

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


@seenivasan - thanks worked great :)



View Postoutrage, on 14 February 2013 - 06:06 PM, said:

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 :)
until I become certain that there is no certainty.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users