Make encoding uniform before comparing strings in PHP

后端 未结 6 1542
攒了一身酷
攒了一身酷 2021-01-20 16:21

I\'m working on a feature which requires me to get the contents of a webpage, then check to see if certain text is present in that page. It\'s a backlink checking tool.

6条回答
  •  不知归路
    2021-01-20 16:44

    If you can't reliably get the encoding, you can use mb_convert_encoding.

    $string1 = mb_convert_encoding($string1, 'utf-8', 'auto');
    $string2 = mb_convert_encoding($string2, 'utf-8', 'auto');
    

    If you can determine the encoding (from the http headers or meta tags) you should specify the encoding instead of using "auto."

    $string1 = mb_convert_encoding($string1, 'utf-8', $encoding1);
    $string2 = mb_convert_encoding($string2, 'utf-8', $encoding2);
    

提交回复
热议问题