无法使用php读取数组中的重音名称
我想检查数组中是否已经存在名称。 我对包含重音字符的名称有问题。 以下是填写(法文)姓名无法使用php读取数组中的重音名称,php,arrays,accent-sensitive,Php,Arrays,Accent Sensitive,我想检查数组中是否已经存在名称。 我对包含重音字符的名称有问题。 以下是填写(法文)姓名Charlène Rodriès和(德文)姓名Jürgen Günter时使用的代码;它输出:不存在 如何捕捉这些包含重音字符的名称 <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['bioname'])) { $bioname = trim(htmlentities($_POST['bionam
Charlène Rodriès
和(德文)姓名Jürgen Günter
时使用的代码;它输出:不存在
如何捕捉这些包含重音字符的名称
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['bioname'])) {
$bioname = trim(htmlentities($_POST['bioname']));
$array = array('John Doe','Bill Cleve','Charlène Rodriês','мария преснякова','Jürgen Günter');
if (in_array($bioname_raw, $array)) { // if bioname already exists
echo '<div">'.$bioname.' ALREADY exists!</div>';
}
else {
echo '<div">'.$bioname.' NOT exists!</div>';
}
}
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<input class="form-control" name="bioname" type="text" placeholder="AUTHORNAME">
<button type="submit" id="cf-submit" name="submit" class="btn btn-primary w-100">POST</button>
</form>
你在比较苹果和桔子
当您执行htmlentities('Charlène Rodriès')
时,它会更改字符串并将其编码为:Charlè;ne Rodri和ecirc;s
,显然与中的Charlène Rodriès
不匹配
因此,从$\u POST变量获取值时,请删除htmlentities()
:
$bioname = trim($_POST['bioname']);
在输出数据之前,仅使用该功能:
echo '<div">'. htmlentities($bioname).' ALREADY exists!</div>';
echo'尝试urldecode
类似:@Slava这是胡说八道,因为调用了htmlentities()