PHP string comparison between two different types of encoding

纵饮孤独 提交于 2019-12-12 11:22:48

问题


I am attempting to match a string I know to a web page title in php.

I have the following string:

ℛobinhood

I have a page title that looks like this:

ℛobinhood

but is actually encoded like this if I look at the <title> element:

&#8475;obinhood

I'm not sure how to compare these two strings. How do I either convert the &#8475; to ℛ or the other way so that I can do a proper comparison?


回答1:


You can use htmlentites ( http://php.net/manual/en/function.htmlentities.php ) to convert to the entity version.




回答2:


Use the multibyte string functions:

  • mb_convert_encoding() to convert both versions to something sane (UTF8, internal encoding)
  • mb_strstr() to do the comparison

mb_* will have an encoding for HTML entities and (most likely) whatever encoding your string is in.



来源:https://stackoverflow.com/questions/8766893/php-string-comparison-between-two-different-types-of-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!