Author: Lars Moelleken
Viewers: 849
Last month viewers: 81
Package: Portable UTF-8
Mostly we are using UTF-8 encoding in our projects and it's working, but if you need to process third party data maybe with unknown encoding it can be painfully. So here comes a auto-detection for this kind of strings.
In "Portable UTF-8" I have implemented a auto-detect character encoding function with support for UTF-16 and UTF-32. So for example if your customer send you a mix of UTF-16 or UTF-8 or ISO ... encoded CSVs you can detect the encoding via:
UTF8::str_detect_encoding('中文空白'); // 'UTF-8' UTF8::str_detect_encoding('Abc'); // 'ASCII'
You can also auto-convert the encoding and this function will also try to fix broken / double encoding, so you can call this function also on a UTF-8 string and you don't mess the string.
UTF8::encode('ISO-8859-1', '-ABC-中文空白-'); // '-ABC-????-' // UTF8::encode('UTF-8', '-ABC-中文空白-'); // '-ABC-中文空白-' // UTF8::encode('HTML', '-ABC-中文空白-'); // '-ABC-中文空白-' // UTF8::encode('BASE64', '-ABC-中文空白-'); // 'LUFCQy3kuK3mlofnqbrnmb0t'
You need to be a registered user or login to post a comment
1,616,398 PHP developers registered to the PHP Classes site.
Be One of Us!
Login Immediately with your account on:
Comments:
No comments were submitted yet.