Solved

htmlentities() does NOT work with html entities

Posted on 2007-03-26
2
279 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
ID: 18793221
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:Vel Eous
ID: 18793225
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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.

856 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