Page 1 of 1

Chinese characters in PHP

Posted: Fri Apr 13, 2012 1:56 am
by irpalo
Client page:

Code: Select all

<head>
<meta http-equiv="Catchup Scheduler" content="text/html; charset=UTF-8">
</head>

<body>
<form action="next.php" method="POST" >
<input type="text" name="programme_name"></br>
<input type="submit">
</form>
</body>
Server page:

Code: Select all

$name = $_POST['programme_name'];

mysql_query("SET character_set_client=utf8",$con);
mysql_query("SET character_set_connection=utf8", $con);
mysql_query("SET character_set_results=utf8", $con);

$query = "Select * from programme where Programme_name Like '%".$name."'";
Problem is even if there is that chinese text in the database results is ZERO(none). If I print the POST value $name it displays the correct text with the chinese characters.

but if i store it in a variable, such as:

Code: Select all

$name= "valuevalue ( 官话 )";
$query = "Select * from programme where Programme_name Like '%".$name."'";
It produces results. how could this be, in POST it doesn't but static value declaration it does? My OS is XP SP3.

Is there a problem in the "internal" representation of chinese characters if it is in POST? Do I need to set something in my OS to support chinese representation?

Re: Chinese characters in PHP

Posted: Fri Apr 13, 2012 10:06 am
by Weirdan
check what the following would return:

Code: Select all

function str_dump($str) { 
    return join(" ", str_split(bin2hex($str), 2)); 
}

var_dump(str_dump("valuevalue ( 官话 )"));
var_dump(str_dump($_POST["programme_name"]));
If the strings are not the same that means you have your encoding messed up somewhere (it could be that browser doesn't send you utf-8 for example)