A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearConvert utf8-characters to iso-88591 and back in PHP - page 1
User InfoPosts
Convert utf8-characters to iso-88591 and back in PHP#1
Some of my script are using different encoding, and when I try to combine them, this has becom an issue.

But I can't change the encoding they use, instead I want to change the encodig of the result from script A, and use it as parameter in script B.

So: is there any simple way to change a string from UTF-8 to ISO-88591 in PHP? I have looked at utf_encode and _decode, but they doesn't do what i want. Why doesn't there exsist any "utf2iso()"-function, or similar?

I don't think I have characters that can't be written in ISO-format, so that shouldn't be an huge issue.

posted date: 2008-12-17 04:40:00

Re: Convert utf8-characters to iso-88591 and back in PHP#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-17 04:40:01

Re: Convert utf8-characters to iso-88591 and back in PHP#3
You need to use the iconv package, specifically its iconv function.

posted date: 2008-12-17 04:56:00

Re: Convert utf8-characters to iso-88591 and back in PHP#4
Have a look at iconv() or mb_convert_encoding().Just by the way: why don't utf8_encode() and utf8_decode() work for you?utf8_decode — Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1utf8_encode — Encodes an ISO-8859-1 string to UTF-8So essentially$utf8 = 'ÄÖÜ'; // file must be UTF-8 encoded$iso88591_1 = utf8_decode($utf8);$iso88591_2 = iconv('UTF-8', 'ISO-8859-1', $utf8);$iso88591_2 = mb_convert_encoding($utf8, 'ISO-8859-1', 'UTF-8');$iso88591 = 'ÄÖÜ'; // file must be ISO-8859-1 encoded$utf8_1 = utf8_encode($iso88591);$utf8_2 = iconv('ISO-8859-1', 'UTF-8', $iso88591);$utf8_2 = mb_convert_encoding($iso88591, 'UTF-8', 'ISO-8859-1');all should do the same - with utf8_en/decode() requiring no special extension, mb_convert_encoding() requiring ext/mbstring and iconv() requiring ext/iconv.

posted date: 2008-12-17 04:58:00

Re: Convert utf8-characters to iso-88591 and back in PHP#5
First of all, don't use different encodings. It leads to a mess, and UTF-8 is definitely the one you should be using everywhere.Chances are your input is not ISO-8859-1, but something else (ISO-8859-15, Windows-1252). To convert from those, use iconv.Nevertheless, utf8_encode and utf8_decode should work for ISO-8859-1. It would be nice if you could post a link to a file or a uuencoded or base64 example string for which the conversion fails or yields unexpected results.

posted date: 2008-12-17 05:02:00

Re: Convert utf8-characters to iso-88591 and back in PHP#6
utf8_decode should exactly be your utf2iso?!?

posted date: 2008-12-17 05:05:00

Re: Convert utf8-characters to iso-88591 and back in PHP#7
Thanks for a good answer, and you and the others here are right: utf8_decode() seems to get the work done. There must have been some problems with files or my browser. At least I'm no longer able to reproduce the errors... (Maybe I did something wrong with my browser-charset-settings?)

posted date: 2008-12-17 11:01:00

Re: Convert utf8-characters to iso-88591 and back in PHP#8
I used:function utf8_to_html ($data) { return preg_replace( array ( '/ä/', '/ö/', '/ü/', '/é/', '/à/', '/è/' ), array ( 'ä', 'ö', 'ü', 'é', 'à', 'è' ), $data );}

posted date: 2009-09-13 10:43:00

Re: Convert utf8-characters to iso-88591 and back in PHP#9
I use this function:function formatcell($data, $num, $fill=" ") { $data = trim($data); $data=str_replace(chr(13),' ',$data); $data=str_replace(chr(10),' ',$data); // translate UTF8 to English characters $data = iconv('UTF-8', 'ASCII//TRANSLIT', $data); $data = preg_replace("/[\'\"\^\~\`]/i", '', $data); // fill it up with spaces for ($i = strlen($data); $i < $num; $i++) { $data .= $fill; } // limit string to num characters $data = substr($data, 0, $num); return $data;}echo formatcell("YES UTF8 String Zürich", 25, 'x'); //YES UTF8 String Zürichxxxecho formatcell("NON UTF8 String Zurich", 25, 'x'); //NON UTF8 String ZurichxxxCheck out my function in my bloghttp://www.unexpectedit.com/php/php-handling-non-english-characters-utf8

posted date: 2010-08-31 09:37:00

Re: Convert utf8-characters to iso-88591 and back in PHP#10
Just for the record: I'd faced some situation like that, but I've noticed the iconv has been called twice (nested) to the same str var. After I removed that first call, works like a charm. (utf8_decode and mb_convert_enconding haven't be used)

posted date: 2012-06-08 13:31:00

Re: Convert utf8-characters to iso-88591 and back in PHP#11
This advice helped me to solve a peculiar problem where a UTF-8 string ("Atlántico") was first literally encoded into ISO-8859-1 (looked like "Atlántico") and then these single-byte characters were reencoded back to UTF-8 (looked exactly the same "Atlántico" but each character was UTF-8 encoded this time). utf8_decode() helped because it decoded the UTF-8 characters into their literal ANSI substitutes which were then somehow mysteriously properly read&displayed as UTF-8 characters. Does it makes sense or not? Hmm..

posted date: 2012-10-24 17:19:00

Re: Convert utf8-characters to iso-88591 and back in PHP#12
function parseUtf8ToIso88591(&$string){ if(!is_null($string)){ $iso88591_1 = utf8_decode($string); $iso88591_2 = iconv('UTF-8', 'ISO-8859-1', $string); $string = mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8'); }}

posted date: 2012-12-07 04:53:00

select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.