FUDforum - خوراک RDF
http://fudforum.org/forum/index.php
encoding
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=186326&th=123551#msg_186326
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
setlocale(LC_CTYPE|LC_COLLATE,"en_GB.UTF8");
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
page.
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.
--
Denis McMahon, denismfmcmahon@gmail.com]]>Denis McMahon2014-06-26T05:50:06-00:00Re: encoding
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=186327&th=123551#msg_186327
> I'm not sure how to fix this. Ideas anyone?
Fix was:
htmlentities( $string, ENT_COMPAT, "UTF-8" );
Not sure if I actually need the setlocale or not. Seems to work without
it.
ENT_HTML5 isn't supported in my server distro's current php (5.3) ...
mutter mutter
--
Denis McMahon, denismfmcmahon@gmail.com]]>Denis McMahon2014-06-26T07:04:05-00:00Re: encoding
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=186328&th=123551#msg_186328
> htmlentities( $string, ENT_COMPAT, "UTF-8" );
>
> Not sure if I actually need the setlocale or not. Seems to work without
> it.
In PHP < 5.4 the default of the 3rd parameter is 'ISO-8859-1', so
setting this parameter appropriately is important when $string may
contain non ASCII characters. For instance: