Solution to the garbled part of the php string: 1. Use "mb_substr(strip_tags($str),0,-1,'UTF-8');" to intercept the string; 2. Use "iconv( "UTF-8","GB2312//IGNORE",$data)" can convert the character set.
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
What to do if the php string part is garbled ?
Solution to garbled characters in PHP strings
If string interception causes garbled strings, use mb_substr to intercept them
Parameters
str Required. Extracts a substring from this string.
start Required. Specifies where in the string to begin.
Positive number - starts at the specified position in the string
Negative number - starts at the specified position from the end of the string
0 - at the first character in the string Start at
length Optional. Specifies the length of the string to be returned. The default is until the end of the string.
Positive number - returned from the position of the start parameter
Negative number - returned from the end of the string
encoding Optional. Character Encoding. If omitted, the internal character encoding is used.
$str = '表现出扎实的基�' $str = mb_substr(strip_tags($str),0,-1,'UTF-8'); echo $str; // 输出内容为 表现出扎实的基
Or use iconv to convert the character set
iconv("UTF-8","GB2312//IGNORE",$data)
ignore means to ignore errors during conversion. If there is no ignore parameter, all strings following the character will not be able to is saved.
Convert character set
$str=mb_convert_encoding('转换内容',"utf-8","GBK");
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if the php string part is garbled. 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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use
