Home > Backend Development > PHP Problem > How to solve the php mbsubstr garbled problem

How to solve the php mbsubstr garbled problem

藏色散人
Release: 2023-03-08 13:36:01
Original
2276 people have browsed it

Solution to php mbsubstr garbled code: First find php.ini in the windows directory; then find ";extension=php_mbstring.dll" and remove the preceding semicolon.

How to solve the php mbsubstr garbled problem

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

Solution to the problem of garbled Chinese characters intercepted by PHP Application of mb_substr function

Using mb_substr to intercept strings will not cause garbled characters, and experts can fly...

First of all

1. Make sure you have the php_mbstring.dll file under Windows/system32. If not, copy it from your Php installation directory extensions into Windows/system32. .

2. Find php.ini in the windows directory, open it for editing, search for mbstring.dll, find ;extension=php_mbstring.dll and remove the ; sign in front, so that the mb_substr function can take effect, and the mb_strcut function can also You can intercept the length of the string. Let’s see the difference in the following example:

The code is as follows:

<?php
$str = &#39;这样一来我的字符串就不会有乱码^_^&#39;;
echo "mb_substr:" . mb_substr($str, 0, 7, &#39;utf-8&#39;);
//结果:这样一来我的字
echo "<br>";
echo "mb_strcut:" . mb_strcut($str, 0, 6, &#39;utf-8&#39;);
//结果:这样
?>
Copy after login

As can be seen from the above example, mb_substr divides characters by words, while mb_strcut Characters are divided by bytes, but half characters will not be produced.

Recommended: "PHP Video Tutorial"

The above is the detailed content of How to solve the php mbsubstr garbled problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template