Get the App
SLTechnology News&Howtos  ›  Development  › 

How to intercept a string from which bit by php

Shulou Source: shulou.com Published: 2022-06-01 17:46:01 10月07日 Update

Editor to share with you how to intercept strings from the first bit of php, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Intercept methods: 1, using the substr () function, syntax "substr (string, intercepting the starting position of the string, intercepting the length of the string)"; 2, using the mb_substr () function, syntax "mb_substr (string, intercepting the starting position of the string, intercepting the length of the string, character encoding)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, to intercept a string from a specified location, you can use the substr () and mb_substr () functions.

Both the substr () and mb_substr () functions can intercept strings. The only difference between them is the handling of Chinese characters. Let's take a look at these two functions.

The substr () function intercepts a string

The substr () function can intercept characters of a certain length from a specified position in a string.

Example:

Substr () function to deal with English is not any problem, but in the development we often deal with more Chinese characters, substr () function can also deal with Chinese, but not very perfect. So how to intercept Chinese characters? You can use the mb_substr () function.

The mb_substr () function intercepts Chinese strings

The mb_substr () function can intercept a specified part from a string. Unlike the substr () function, the mb_substr () function is valid not only for English characters, but also for Chinese characters.

Use skills:

Use the mb_substr () function to intercept a string of specified length, using "..." for the excess. Instead.

The above is all the content of the article "how to intercept strings from php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Character string function utf-8 Chinese location length processing article valid content grammar English learning starting different not much two using skills online learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Shulou Information Shulou Tech Info Xiaomi