这是我的代码:
<HTML>
<head>
<title>Building a Form</title>
</head>
<body>
<?php
$search=htmlentities($_GET["search"]);
$self=htmlentities(urldecode($_SERVER['PHP_SELF']));
if($search=='')
{
echo ('
<form action="'.$self.'" method="get">
<label>
Search: <input type="text" name="search"/>
</label>
<input type="submit" value="Go!"/>
</form>');
}else
{
echo "The search string is:<strong>$search</strong>";
}
?>
</body>
</HTML>
<HTML>
<head>
<title>Building a Form</title>
</head>
<body>
<?php
$search=htmlentities($_GET["search"]);
$self=htmlentities(urldecode($_SERVER['PHP_SELF']));
if($search=='')
{
echo ('
<form action="'.$self.'" method="get">
<label>
Search: <input type="text" name="search"/>
</label>
<input type="submit" value="Go!"/>
</form>');
}else
{
echo "The search string is:<strong>$search</strong>";
}
?>
</body>
</HTML>
输出:
The search string is:ä¸æ��
建议你使用GBK,或者UTF-8编码。可以在 <head> 标签内增加一个 <meta> 声明编码
<meta http-equiv="charset" content="UTF-8">
<HTML>
<head>
<meta http-equiv="charset" content="UTF-8">
<title>Building a Form</title>
</head>
<body>
结果一样,这是为什么呀?
$search=htmlentities($_GET["search"], ENT_QUOTES, 'UTF-8');