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: 6
£

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 offline
No strings attached
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 4,625 requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 20 h 5 m 32 sec
Reputation Power: 1898
Send a message via MSN to 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.
__________________
How to ask a question

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: 6
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 offline
No strings attached
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 4,625 requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 20 h 5 m 32 sec
Reputation Power: 1898
Send a message via MSN to requinix
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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT