PHP: Dealing special characters with iconv -
i still don't understand how iconv
works.
for instance,
$string = "löic & rené"; $output = iconv("utf-8", "iso-8859-1//translit", $string);
i get,
notice: iconv() [function.iconv]: detected illegal character in input string in...
$string = "löic";
or $string = "rené";
i get,
notice: iconv() [function.iconv]:
detected incomplete multibyte character in input string in.
i nothing $string = "&";
there 2 sets of different outputs need store them in 2 different columns inside table of database,
i need convert
löic & rené
loic & rene
clean url purposes.i need keep them -
löic & rené
löic & rené
convert themhtmlentities($string, ent_quotes);
when displaying them on html page.
i tried of suggestions in php.net below, still don't work,
i had situation needed characters transliterated, others ignored (for weird diacritics ayn or hamza). adding //translit//ignore seemed trick me. transliterates able transliterated, throws out stuff can't be.
so:
$string = "ʿabbĀsĀbĀd"; echo iconv('utf-8', 'iso-8859-1//translit', $string); // output: [nothing, , notice] echo iconv('utf-8', 'iso-8859-1//ignore', $string); // output: abbsbd echo iconv('utf-8', 'iso-8859-1//translit//ignore', $string); // output: abbasabad // yay! that's wanted!
and another,
andries seutens 07-nov-2009 07:38 when doing transliteration, have make sure lc_collate set, otherwise default posix used. transform "rené" "rene" use following code snippet: setlocale(lc_ctype, 'nl_be.utf8'); $string = 'rené'; $string = iconv('utf-8', 'ascii//translit', $string); echo $string; // outputs rene
how can work them out?
thanks.
edit:
this source file test code,
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" class="no-js"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <?php $string = "löic & rené"; $output = iconv("utf-8", "iso-8859-1//translit", $string); ?> </html>
and did save source file in utf-8 encoding? if not (and guess didn't since produce "incomplete multibyte character" error), try first.
Comments
Post a Comment