htmlentites() bug?

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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

htmlentites() bug?

Post 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.
spider.nick
Forum Commoner
Posts: 72
Joined: Wed Jul 15, 2009 12:22 pm
Location: Overland Park, KS

Re: htmlentites() bug?

Post 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
spider.nick
Forum Commoner
Posts: 72
Joined: Wed Jul 15, 2009 12:22 pm
Location: Overland Park, KS

Re: htmlentites() bug?

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: htmlentites() bug?

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: htmlentites() bug?

Post 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.
spider.nick
Forum Commoner
Posts: 72
Joined: Wed Jul 15, 2009 12:22 pm
Location: Overland Park, KS

Re: htmlentites() bug?

Post 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
Post Reply