In PHP, you can use the "mb_substr" function to get the first few digits of a text. This function is used to return a part of a string. It is often used to split Chinese text. You can return the first few digits of a text string by setting parameters. bit, the syntax is "mb_substr("text",0,first few digits)".
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
How to get the first few digits of text in php
The mb_substr() function returns a part of the string. We have learned the substr() function before. It only targets English characters. If you want to split Chinese characters, 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.
Syntax
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, and if it fails, it will be returned FALSE, or returns an empty string.
The example is as follows:
<?php echo mb_substr("这是需要截取的文字前几位这是不需要截取的文字后几位", 0, 12); // 输出:这是需要截取的文字前几位 ?>
Output result:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to get the first few characters of text in php. 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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor
