PHP implements the solution to intercept Chinese strings without the ? sign_php tips

墨辰丷
Release: 2023-03-28 09:40:02
Original
1158 people have browsed it

This article mainly introduces the solution for PHP to intercept Chinese strings without the ? sign, involving PHP string traversal and encoding conversion and other related operating techniques. Friends in need can refer to it

The details are as follows :

When PHP intercepts a mixed string of Chinese and English, the last Chinese character is often split into two halves, for example: intercepting the first 18 characters of the string

"; ?>
Copy after login

The output is:

1欢迎访问新浪?BR>
Copy after login

So I wrote the following code to determine if the Chinese character bytes in a mixed Chinese and English string If the number is an odd number, one less byte will be intercepted to ensure complete display of Chinese characters.

 127) { $value_count++; } } if ($value_count % 2 != 0) { $value = substr($text, 0, $value_length - 1); } echo $value."
"; ?>
Copy after login

The output is:

1欢迎访问sina新浪
Copy after login

and above That’s the entire content of this article, I hope it will be helpful to everyone’s study.


Related recommendations:

Detailed explanation of how to intercept the length ofstringin PHP

PHPStringReverse order implementation method

php implementation to obtain a specified number of randomstringmethod

The above is the detailed content of PHP implements the solution to intercept Chinese strings without the ? sign_php tips. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!