mardi 4 août 2015

How to convert "UCS-2" to "UTF-8" by this way, with HTML, in PHP?

I have a HTML form, which is set in ISO-8859-1. Now, I want to convert UCS-2 string into UTF-8 string; this output UTF-8 will print into <input type="text" name="out" />. And, my HTML form must not be changed the character set.

I have read these questions:

I try to solve my problem by this code:

<?php $str = $_POST['str']; ?>
<form method="post">
<input type="text" name="str" value="<?php echo $str; ?>" />
&nbsp;&nbsp;<input type="submit" />
</form>
<hr /><input type="text" name="out" value="<?php echo mb_convert_encoding($str, 'UCS-2', 'UTF-8'); ?>" />

When I input a word in UCS-2, such as: Việt Nam, it will returns: �V�i�&�#�7�8�7�9�;�t� �N�a�m. Why?

Is there any way to convert UCS-2 to UTF-8, by PHP; then, output into <input type="text" name="out" />?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire