Solved

htmlentities() does NOT work with html entities

Posted on 2007-03-26
2
274 Views
Last Modified: 2012-06-22
Hello,

I need to clean user-inputed text so I use htmlentities() however it does NOT work if html entities have already been provided.

Here is an example:

         echo htmlentities("Copyright © 2007    CompanyName®");

How should I solve this?
0
Comment
Question by:hankknight
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
Comment Utility
To have a save function you will need to use a white list. First use htmlentities on the string, then replace valid strings with their original entitiy
$str = htmlentities("Copyright © 2007    CompanyName®");
$str =strtr($str, array('©', ' '), array('©', ' '));
Other thing might be to use a regular rexpression, but don't know if this might allow tricky strings to be unescaped:
$str = preg_replace('/&(\w+);/', '&\1;', $str);
0
 
LVL 14

Expert Comment

by:Tchuki
Comment Utility
htmlentities only takes the HTML tags and replaces them with their markup eqivalents.

Try using the PHP strip_tags method:

http://uk3.php.net/strip-tags

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now