Page 1 of 1

htmlentities()

Posted: Sun Apr 30, 2006 6:32 am
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

Posted: Sun Apr 30, 2006 6:52 am
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

Posted: Sun Apr 30, 2006 7:07 am
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!

Posted: Sun Apr 30, 2006 7:23 am
by gowilson
Hi

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

The function IS working.

Posted: Sun Apr 30, 2006 7:23 am
by shiznatix
is the data stored in the database already been html-entitied?