Solved

htmlentities() does NOT work with html entities

Posted on 2007-03-26
2
275 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:Tchuki
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Echo vs ?><?php  html code 4 47
Php pie charts 3 26
Regex PHP lines with newlines not being matched - all other match fine 4 23
mysql between clause 2 10
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

25 Experts available now in Live!

Get 1:1 Help Now