为什么这两个字符串在PHP中不一样?

时间:2016-05-18 06:25:08

标签: php

这是我的代码:

$city = $_GET['city'];
$cityfinal = htmlentities($city, ENT_QUOTES | ENT_IGNORE, "UTF-8");

similar_text($cityfinal, "CITY OF BIÑAN", $percent); 

echo "Differnce between " . $cityfinal . " and CITY OF BIÑAN is " . $percent; 

结果:

  

CITY OFBIÑAN与CITY OFBIÑAN的区别是72.7272727273

1 个答案:

答案 0 :(得分:1)

您的比较字符串未转换为htmlentities,因此它会给您带来差异。尝试转换并检查。

此处特殊字符BIÑAN$_GET['city']字符串编码,但保留给定的比较字符串。

$city = $_GET['city'];
$checkcity ="CITY OF BIÑAN";
$cityfinal = htmlentities($city, ENT_QUOTES | ENT_IGNORE, "UTF-8");
$cityCheckwith = htmlentities($checkcity, ENT_QUOTES | ENT_IGNORE, "UTF-8");

similar_text($cityfinal, $cityCheckwith, $percent); 

echo "Differnce between " . $cityfinal . " and CITY OF BIÑAN is " . $percent; 

<强>输出

  

CITY OF BIAN和CITYOFBIÑAN之间的差异是100

查看在线演示:Click Here