htmlentities()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gowilson
Forum Newbie
Posts: 3
Joined: Sun Apr 30, 2006 6:28 am

htmlentities()

Post by gowilson »

Hi

I am having problems with htmlentitites() and am hoping someone can offer me advice.

Basically, I'm developing an application to take mySQL data and present it on a web page using a table, the problem I have is with converting special characters such as a quote to their ASCII equivalent. The data looks fine on the web but it isn't valid XHTML because it doesn't use proper ASCII codes.

Example: Don't order with this supplier

Should be translated to: Don't order with this supplier

I've tried using htmlentities but it doesn't make any difference.

The code I'm using is htmlentities($row['suppliercomments'], ENT_QUOTES)

Does anyone have any advice?

Thanks
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Post by someberry »

It will convert it, but your browser will display it as a single quote.

Code: Select all

<?PHP
$original = "Don't order with this supplier";

echo($original . '<br />' .
htmlentities($original,ENT_QUOTES));
?>
Turns into:

Don't order with this supplier<br />
Don't order with this supplier
gowilson
Forum Newbie
Posts: 3
Joined: Sun Apr 30, 2006 6:28 am

Post by gowilson »

someberry wrote:It will convert it, but your browser will display it as a single quote.

Code: Select all

<?PHP
$original = "Don't order with this supplier";

echo($original . '<br />' .
htmlentities($original,ENT_QUOTES));
?>
Turns into:

Don't order with this supplier<br />
Don't order with this supplier
Hi

Thanks for your quick response.

I see the logic in the above example and it correctly displays a single quote and if you view the HTML source you can see that the ascii code has been inserted properly.

The problem is that this does not work for data from a database. e.g. htmlentities($row['supplier'],ENT_QUOTES)

Maybe I am missing something!
gowilson
Forum Newbie
Posts: 3
Joined: Sun Apr 30, 2006 6:28 am

Post by gowilson »

Hi

Ignore me, the problem would appear to be with client data!

The function IS working.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

is the data stored in the database already been html-entitied?
Post Reply