Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get the first few bits of text by php

Shulou Source: shulou.com Published: 2022-06-01 16:16:29 10月02日 Update

This article will explain in detail how php obtains the first few words for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

In PHP, you can use the "mb_substr" function to get the first few bits of the text, this function is used to return part of the string, often used to split Chinese text, by setting parameters can return the first few bits of the text string, the syntax is "mb_substr (" text ", 0, the first few digits)".

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

How to get the first few bits of text by php

The mb_substr () function returns a portion of the string. We learned about the substr () function before, which is only for English characters. If you want to split the Chinese text, you need to use mb_substr ().

Note: if the start parameter is negative and length is less than or equal to start, length is 0.

Grammar

Mb_substr (string $str, int $start [, int $length = NULL [, string $encoding = mb_internal_encoding ()]]): string

The parameter settings are as follows:

The result returned is the extracted part of the string, or FALSE if it fails, or an empty string.

Examples are as follows:

Output result:

This is the end of this article on "how to get the first few words in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Text characters functions strings parameters articles more results grammar Chinese good practical digits content that is tutorials articles comments environment computer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Apple Shulou Technology Microsoft