Kashif Latif
Kashif Latif

Reputation: 677

Remove Tags from string, Stored from ckeditor

I'm trying to echo value in PHP, which is stored in database using ckeditor, the value stored in database is something like

<p>sample text</p>

now im printing value using

<?php echo $row[0]->content; ?>

but the output I'm getting is

<p>sample text</p>

how to remove p tags from string?

Upvotes: 2

Views: 4415

Answers (1)

u_mulder
u_mulder

Reputation: 54841

String &lt;p&gt;sample text&lt;/p&gt; includes some encoded html entities (&lt; for < and &gt; for >).

If you want to replace this encoded entitites with real symbols - use html_entity_decode. After it, your string becomes <p>sample text</p>. So if you echo it, <p> and </p> will be considered html-tags and will not be shown.

If you still need to remove these tags - use strip_tags function.

In the end:

<?php echo strip_tags(html_entity_decode($row[0]->content)); ?>

And yes, strip_tags removes all tags from a string unless you use it's second parameter.

Upvotes: 4

Related Questions