Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » encoding
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Return to the default flat view Create a new topic Submit Reply
encoding [message #186326] Thu, 26 June 2014 01:50 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Senior Member
add to buddy list
ignore all messages by this user
Tear my hair out time.

I have a csv file that contains text strings that I wish to display in a
web page.

The csv file is utf-8, and the text strings include the british pound
symbol encoded as two bytes 0xc2/0xa3

I'm using


before reading the csv file, which I hope means that the csv file is read
as utf-8.

Then I feed the string through htmlentities() before adding it to the web

However, the web page that arrives at the client has £
instead of just £.

I'm not sure where it's going wrong, partly because right now I may be
too tired to work out where and how I can inspect the string without
character encodings getting in the way.

If I print_r the data that has been read in to the web page, that shows
ok, but at that point it's still utf-8, not an html entity.

The following is at http://www.sined.co.uk/tmp/pound.php and seems to
demonstrate the issue:

setlocale(LC_CTYPE|LC_COLLATE, "en_GB.UTF8");
$str1 = "\xc2\xa3";
$str2 = htmlentities( "$str1" );
echo <<< EOT
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Broken Pound</title>
Original: {$str1}
Entities: {$str2}

I'm not sure how to fix this. Ideas anyone?

Denis McMahon, denismfmcmahon(at)gmail(dot)com
[Message index]
Read Message
Read Message
Read Message
Previous Topic: SplFileObject always returns an extra "last" line -- why?
Next Topic: how to revise my User Contributed Note on php.net
Goto Forum:

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Sep 20 16:33:20 EDT 2018

Total time taken to generate the page: 0.00589 seconds