0

I am having some trouble with strings which I get from my database. These strings include various html tags in them as well. For example:

"<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard</p>" 

This is what I get from the database. How do I get rid of the <p> tags in it? I have already tried strip_tags and other functions to no avail.

These tags do not show up in the tinymce textareas and the tags work there respective functionalities.

3
  • Are the tags escaped? They are escaped when they are visible in your normal HTML output, and not parsed as tags. Commented Jul 28, 2011 at 9:10
  • 3
    You say that you want to get rid of the tags. In the next sentence you say that the tags dont show up. Explain please? Commented Jul 28, 2011 at 9:12
  • 1
    Pretty sure strip_tags works for removing tags :S Please show us the code that doesn't work and tell us what it's supposed to do. Commented Jul 28, 2011 at 9:14

3 Answers 3

2

Use this function it will help you

function convertSpecialChars($string) {
    $string = str_replace("&", "&amp;", $string);
    $string = str_replace("\n", "&#xA;", $string);
    $string = str_replace("‘", "&apos;", $string);
    $string = str_replace(">", "&gt;", $string);
    $string = str_replace("<", "&lt;", $string);
    $string = str_replace("“", "&quot;", $string);
    return $string;
}

enjoy...

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

1 Comment

this has helped a lot now i use this $text = str_replace("&gt;", ">", $string); $text = str_replace("&lt;", "<", $text); echo $strip_tags($text); and it has worked. Thankx alot sir
2

strip_tags() if you want to remove HTML and PHP tags.

htmlspecialchars() if you want to keep HTML tags, but remove XSS possibility.

Comments

1

If I understod you correctly, you want to apply htmlentities.

3 Comments

i tried this as well. it does convert the tags,outputs '&lt;p&gt;' in place of the tags.. which means htmlentities reads the tags but strip slashes does not.
@Hammad: Maybe you could tell us what output you expect using some concrete desired result to your example?
@marc.. i wanted the output to be the simple text within the tags/ or simply the whole text without the html tags etc.. sorry if i sounded confused. thankx a lot though

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.