php string conversion encoding method: 1. The general iconv function performs string conversion encoding; 2. Use the "mb_convert_encoding" function to handle multi-byte encoding conversion.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.
php String encoding conversion
php provides two string conversion encoding functions, one is a general iconv function, and the other is a multi-byte encoding conversion function mb_convert_encoding, you need to enable the extension php_mbstring
string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )
Use:
It is found that iconv will make an error when converting the character "-" to gb2312. If there is no ignore parameter, all strings following this character cannot be save. No matter what, this "-" cannot be converted successfully and cannot be output. In addition, mb_convert_encoding does not have this bug.
mb_convert_encoding can specify multiple input encodings, which will be automatically recognized based on the content, but the execution efficiency is much worse than iconv;
如:s t r = m b c o n v e r t e n c o d i n g ( str = mb_convert_encoding(str=mb convert encoding(str,“euc-jp”,“ASCII,JIS,EUC-JP,SJIS,UTF- 8”);“ASCII,JIS,EUC-JP,SJIS,UTF-8”的顺序不同效果也有 差异
Generally use iconv, only Use the mb_convert_encoding function when you are unable to determine what the original encoding is, or the iconv conversion cannot be displayed normally.
Example:
$content = iconv(“GBK”, “UTF-8”, c o n t e n t ) ; ‘ ‘ content); ` `content);‘‘content = mb_convert_encoding($content, “UTF-8”, “GBK”);`
[Recommended learning: PHP video tutorial】
The above is the detailed content of How to convert encoding in php string. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
