samedi 31 janvier 2015

Character encoding/decoding returns ? signs or weird results when form is submitted


Vote count:

0




I know there are many similar posts about this but so far I couldn't solve my problem although I went thru them. I'm trying to print exact search keywords when I hit Search button but unfortunately I'm seeing encoded versions and I cannot decode. I read up on utf8_decode and iconv but no luck so far. I have many languages being used in my site but I'm only struggling with the chars below.


Note: I'm using utf8mb4_unicode_ci as collation in MySQL and same keywords were inserted into table as Ç, Ğ, İ, Ö, Ş, Ü, ç, ğ, ı, ö, ş, ü so because of encoding differences, search will fail in most case.


SEARCH KEYWORD: Ç, Ğ, İ, Ö, Ş, Ü, ç, ğ, ı, ö, ş, ü


SITE



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form method="post" action="search.php">
Keyword: <input type="text" name="keywords" />
<button type="submit" class="btn btn-default">Search</button>
</form>
</body>
</html>


search.php



echo $_POST['keywords'];
echo '<br />';
echo utf8_decode($_POST['keywords']);
echo '<br />';
echo iconv("ISO-8859-1", "UTF-8", $_POST['keywords']);


CURRENT OUTPUT



Ç, Ğ, İ, Ö, Ş, Ü, ç, ğ, ı, ö, ş, ü
Ç, ?, ?, Ö, ?, Ü, ç, ?, ?, ö, ?, ü
Ç, Ğ, İ, Ö, Ş, Ü, ç, ğ, ı, ö, ş, ü


asked 2 mins ago

inanzzz

1,465






Character encoding/decoding returns ? signs or weird results when form is submitted

Aucun commentaire:

Enregistrer un commentaire