比较两个不同编码的字符串


Compare 2 strings with different encoding

如何使以下字符串相等:

$str1 = "Première équation";
$str2 = "Première équation"; 

我尝试了html_entity_decode($str1),但它不工作

我会使用strcmphtml_entity_decode的组合进行二进制安全比较。

<?php
$str1 = "Première &eacute;quation";
$str2 = "Première équation"; 
var_dump( strcmp(html_entity_decode($str1), $str2) );

https://eval.in/551298

例如;

// Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
if( strcmp(html_entity_decode($str1), $str2) === 0 ) {
   echo "They match";
}