Page 1 of 1

htmlentites() bug?

Posted: Mon Jul 27, 2009 4:07 pm
by jackpf
Hello, and thanks for reading :)

Basically, I decided to run htmlentities() with the 'UTF-8' parameter since that's the encoding I use for my html.

However, I recently noticed that it would not return anything if the string included a pound symbol. I don't know if this is a php bug or what...but check this out:

Code: Select all

echo htmlentities('£'); //outputs "£"
echo htmlentities('£', ENT_QUOTES, 'UTF-8'); //outputs nothing
echo htmlentities('something without a pound symbol <>', ENT_QUOTES, 'UTF-8'); //outputs "something without a pound symbol <>"
I don't understand :dubious:

Thanks for any clarification,
Jack.

Re: htmlentites() bug?

Posted: Mon Jul 27, 2009 4:25 pm
by spider.nick
jackpf wrote:Hello, and thanks for reading :)

Basically, I decided to run htmlentities() with the 'UTF-8' parameter since that's the encoding I use for my html.

However, I recently noticed that it would not return anything if the string included a pound symbol. I don't know if this is a php bug or what...but check this out:

Code: Select all

echo htmlentities('£'); //outputs "&pound;"
echo htmlentities('£', ENT_QUOTES, 'UTF-8'); //outputs nothing
echo htmlentities('something without a pound symbol <>', ENT_QUOTES, 'UTF-8'); //outputs "something without a pound symbol <>"
I don't understand :dubious:

Thanks for any clarification,
Jack.
Well, I have looked into this some. I was reading something and it was talking about how it could not get anything with the &text; version of ascii to work in UTF-8. That prompted me to try this:

Code: Select all

htmlentities('©', ENT_COMPAT, 'UTF-8')
Which, does not work.

Nick

Re: htmlentites() bug?

Posted: Mon Jul 27, 2009 4:31 pm
by spider.nick
McInfo wrote:Your PHP file may not be encoded in UTF-8.
Not the issue. I did:

Code: Select all

echo htmlentities('&', ENT_QUOTES, 'UTF-8')
And it ouputted &

Nick

Re: htmlentites() bug?

Posted: Mon Jul 27, 2009 6:45 pm
by jackpf
Oh yeah...nice work :D


What did you do differently with the two files may I ask? The code is exactly the same...how did you encode them differently?

Re: htmlentites() bug?

Posted: Mon Jul 27, 2009 8:06 pm
by jackpf
Aha, notepad++ can do that as well :D (under Format in case any one is wondering).

Cool - I never knew file encoding made such a difference. Thanks for the info and examples.

Re: htmlentites() bug?

Posted: Tue Jul 28, 2009 8:48 am
by spider.nick
McInfo wrote:Attached, you will find a ZIP archive containing two PHP files. Both files contain the same script. The only difference is the file encoding. One uses UTF-8; the other uses ISO-8895-1. The UTF-8 file displays "&pound;"; the ISO-8895-1 file displays nothing.
My profuse apologies. I did not try out your files, but I will take your word on it.

I use phpDesigner, which also allows you to change the file encoding.

Good Work! :bow:

Nick