3

I have a field in database which contains html tags. I want to show that field in the view without showing HTML tags. I used str_limit($value, $limit = 100, $end = '...') but it shows the html tags also. Any idea?

2 Answers 2

3

Use the strip_tags() function.

For example this filters the <b></b> tags:

<?php
echo strip_tags("Hello <b>world!</b>");
?>

In your case would be something along the lines of:

<?php
   strip_tags($value);
?>

See the documentation.

Check this answer.

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

Comments

0

str_limit only limits the number of characters. What you need to do is parse the database string and remove anything that looks like a tag. I've never used it, but the php strip_tags function might be more what you're looking for.

2 Comments

Thank you for the answer. Do you know any sample that shows that?
I might also add that if you're stripping tags for security measures (which is extremely important!), this method is not sufficient. htmlspecialchars() is much more effective for this, but alone is still prone to problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.