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 an illegal character in input string in...
$string = "Löic";
or $string = "René";
I get,
Notice: iconv() [function.iconv]:
Detected an incomplete multibyte character in input string in.
I get nothing with $string = "&";
There are two sets of different outputs I need store them in the two different columns inside the table of my database,
I need to convert Löic & René
to Loic & Rene
for clean url purposes.
I need to keep them as they are - Löic & René
as Löic & René
then only convert them with htmlentities($string, ENT_QUOTES);
when displaying them on my html page.
I tried with some of the suggestions in php.net below, but still don't work,
I had a situation where I needed some characters transliterated, but the others ignored (for weird diacritics like ayn or hamza). Adding //TRANSLIT//IGNORE seemed to do the trick for me. It transliterates everything that is able to be transliterated, but then throws out stuff that can't be.
So:
$string = "ʿABBĀSĀBĀD"; echo iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $string); // output: [nothing, and you get a 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 what I wanted!
and another,
Andries Seutens 07-Nov-2009 07:38 When doing transliteration, you have to make sure that your LC_COLLATE is properly set, otherwise the default POSIX will be used. To transform "rené" into "rene" we could use the following code snippet: setlocale(LC_CTYPE, 'nl_BE.utf8'); $string = 'rené'; $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string); echo $string; // outputs rene
How can I actually work them out?
Thanks.
EDIT:
This is the source file I test the 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>
The iconv() function is an inbuilt function in PHP which is used to convert a string to requested character encoding.
The iconv() function converts a sequence of characters in one character encoding to a sequence of characters in another character encoding.
The iconv() function in R is used to convert given character vectors between encodings.
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', utf8_encode($s));
And did you save your source file in UTF-8 encoding? If not (and I guess you didn't since that will produce the "incomplete multibyte character" error), then try that first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With