PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 10th, 2008, 04:20 PM
gsoper gsoper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 147 gsoper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 37 m 36 sec
Reputation Power: 5
£

I have a form that users can fill in and the content is displayed elsewhere as HTML. For this reason I use htmlentities() to encode any characters that need it. I'm having problems with the £ symbol which is coming out as £ . From Googling for "£" I can see that this is a common problem! I'm guessing it's to do with character sets but this is an area I have no experience in.

Can anyone advise?

Thanks,
Geoff

Last edited by gsoper : January 10th, 2008 at 04:23 PM. Reason: This forum has issues dealing with html entities!

Reply With Quote
  #2  
Old January 10th, 2008, 06:29 PM
requinix's Avatar
requinix requinix is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2007
Posts: 2,682 requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 21945 Folding Title: Starter FolderFolding Points: 21945 Folding Title: Starter Folder
Time spent in forums: 2 Months 5 Days 14 h 43 m 56 sec
Reputation Power: 458
In general, if you see a capital A plus some accent followed by another character - that is, two characters when you expect one - it's a Unicode/UTF-* problem.

£ is Unicode 0xA3 or binary 0b10100011. This was encoded into two bytes using Unicode: the format is 0b110----10------.
With padded zeros, 0xA3 is 0b00010100011 which then fits into the two-byte pattern above as 0b1100001010100011, or 0xC2A3. This forms the character string £ that you see.

In other words, PHP's utf8_decode() function should fix the problem.
__________________
I'll do something with this space when I remember to.

Reply With Quote
  #3  
Old January 10th, 2008, 08:21 PM
gsoper gsoper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 147 gsoper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 37 m 36 sec
Reputation Power: 5
Quote:
Originally Posted by requinix
In general, if you see a capital A plus some accent followed by another character - that is, two characters when you expect one - it's a Unicode/UTF-* problem.

£ is Unicode 0xA3 or binary 0b10100011. This was encoded into two bytes using Unicode: the format is 0b110----10------.
With padded zeros, 0xA3 is 0b00010100011 which then fits into the two-byte pattern above as 0b1100001010100011, or 0xC2A3. This forms the character string £ that you see.

In other words, PHP's utf8_decode() function should fix the problem.


OK, so in the case of htmlentities() should I set the optional charset parameter to 'UTF-8'? Also, should I be adding a charset to the HTML form?

Thanks,
Geoff

Reply With Quote
  #4  
Old January 10th, 2008, 08:42 PM
requinix's Avatar
requinix requinix is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2007
Posts: 2,682 requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)requinix User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 21945 Folding Title: Starter FolderFolding Points: 21945 Folding Title: Starter Folder
Time spent in forums: 2 Months 5 Days 14 h 43 m 56 sec
Reputation Power: 458
I believe so, yes (to both): your HTML should specify a charset anyways.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > £


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway