php correctly convert between encodings

2020-04-19 07:36发布

I've just spent the last 3 hours tracking down a display problem on one of my pages. The text was a garbled mess. The problem turned out to be the use of utf8_encode on an existing utf8 string. As noted in the docs it can only convert ISO-8859-1. Why does it have such a misleading name? /rant.

What is the proper, less error prone, way of detecting and converting encodings in PHP?

标签: php unicode
1条回答
一夜七次
2楼-- · 2020-04-19 08:33

Either mb_convert_encoding or iconv, depending on what's installed on your server. (iconv is enabled by default, however, mbstring is not.)

查看更多
登录 后发表回答