-3

I am trying to display short description without any markup in read-more section. I want to display small portion of content.

Content Looks like:

This is my car. This may be a funny content. This is a demo text. This is a demo text.

This is a demo text. This is a demo text. This is a demo text. This is a demo text. This is a demo text. This is a demo text.

Readmore Looks Like:

This is my car. This may be a funny content.

My question is how to remove the effect of html and display a normal string.

2
  • If you want to preserve the actual content, but remove the HTML tags, you can use strip_tags() function php.net/manual/en/function.strip-tags.php - this preserves the original text (just removes the formatting) though. Commented Jan 2, 2017 at 17:39
  • 2
    You just apply strip_tags() to the "read more" portion of it, not the entire string. Although if you want to remove the style of the HTML attributes, put it all into a div which you style in a way that it becomes normal text inside it. Commented Jan 2, 2017 at 17:51

1 Answer 1

1

Following your example, your input string will look like this:

<b>This is my car.</b> <em>This may be a <strike>funny</strike> content.</em>
<p>This is a demo text. This is a demo text.</p>

let's consider this is going to be inside a variable $mystring

echo $mystring;

This is my car. This may be a funny content.

with strip_tags function and only $mystring as parameter you remove all the tags:

echo strip_tags($mystring);

This is my car. This may be a funny content.

you can also exclude some of the tags you wanna keep, for example:

echo strip_tags($mystring,"<strike>");

This is my car. This may be a funny content.

In your situation probably this last option will be useful if you want to keep some tags and replacing them manually (for example br with \n ...)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.