iconv


php apg

CONVERTS a given STRING to a requested character encoding.





This function will be used in next exercises.



<?php

str
|false iconv str $from_encoding 
                         
str $to_encoding 
                         
str $string )


where,

$from_encoding The input charset

 $to_encoding 
The output charset

$string 
The STRING to be converted

?>

 $from_encoding 


The input charset.



 $to_encoding 


The output charset.



 $string 


The STRING to be converted.





Transliteration is actvated if appended by the string  //TRANSLIT  to $to_encoding.

This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters.

If the string  //IGNORE  characters that cannot be represented in the target charset are silently discarded.

Otherwise, E_NOTICE is generated and the function will return FALSE.


Some implementations are known to ignore  //TRANSLIT , so the conversion is likely to fail for characters which are illegal for the $to_encoding.



  1 EXERCISE   

<?php

$str01 
'Dies ist ein Beispiel für die Anwendung der iconv-Funktion in deutscher Sprache.';

$in_chrs01 'UTF-8';

$out_chrs01 'Windows-1255//TRANSLIT';

$strr01 iconv($in_chrs01$out_chrs01$str01);

echo 
$strr01 '<br><br>';

?>

  2 EXERCISE   

<?php

setlocale
(LC_CTYPE"de""de-de""de_DE");

$str02 'Dies ist ein Beispiel für die Anwendung der iconv-Funktion in deutscher Sprache.';

$in_chrs02 'Windows-1255';

$out_chrs02 'UTF-8';

$strr02 iconv($in_chrs02$out_chrs02$str02);

echo 
$strr02 '<br><br>';

?>