Home >Backend Development >PHP Tutorial >Detailed explanation of how to intercept string length in PHP

Detailed explanation of how to intercept string length in PHP

墨辰丷
墨辰丷Original
2018-05-26 15:44:402058browse

This article mainly introduces the usage of intercepting string length in PHP, and analyzes the relevant operating techniques and precautions for the mb_substr function to intercept Chinese strings in the form of examples. Friends in need can refer to this article

The example describes the usage of intercepting the string length in PHP. Share it with everyone for your reference, the details are as follows:

php provides many functions, among which the string interception function is no exception, and the function is also very powerful.

<?php
//文件编码格式为UTF-8
$str=&#39;在公园船上,有一个漂亮的女孩,如果在湖中央发生点什么……&#39;;
echo mb_substr($str,0,7,&#39;UTF-8&#39;);//这里设置显示字符串的编码格式 //输出&#39;在公园船上,有&#39;
echo mb_substr($str,3,7,&#39;UTF-8&#39;);//这里设置显示字符串的编码格式 //输出&#39;船上,有一个漂&#39;
?>

You must pay attention to the encoding format here. Improper handling may cause garbled characters.

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHPStringReverse order implementation method

php implements the method of obtaining a specified number of random strings

php implements custom interception of Chinese strings -utf8 version

The above is the detailed content of Detailed explanation of how to intercept string length in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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