在 PHP 中比较字符串并非一直有效


Comparing strings in PHP does not work all the time?

我有这个代码:

if($post['maintopics'] == '-1--- Bitte wählen Sie ein Thema aus --' && $post['subtopics'] == 'Bitte wählen Sie erst eine Oberkategorie...') {
                echo 'test';
}

在我的本地Windows上,它打印"test",Linux服务器上的相同代码不打印"test"。我尝试在执行 if 之前记录值,它们与 if 中的值完全相同。知道为什么这在我的服务器上不起作用吗?

谢谢

尝试在文件的开头定义它:

ini_set( 'default_charset', 'UTF-8' );
mb_internal_encoding('UTF-8');

此外,请检查您是否在没有 BOM 的情况下以 UTF-8 格式保存 PHP 文件,Notepad++ 是一个不错的选择。

如果恳求的话,我也有些头疼,希望能帮到你。