Twitter PHP API error “One or more parameters contains an invalid UTF-8 sequence”

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

After upgrading to Twitter’s new 1.1 API. My program stopped working and threw http 400 error with description “One or more parameters contains an invalid UTF-8 sequence”.

I discovered that it was because I was using substrfunction in php to cut Chinese characters with UTF8 encoding.

when using substr(), it will create some messy code on languages other than English. In situations like this, it’s better to use mb_substr() or mb_strcut.
For example:


From the above example, it's clear to see that mb_substr cuts sentense by actual characters,mb_strcut cuts string by byte

Read More