Home  >  Article  >  Backend Development  >  Usage example of intercepting string length in PHP

Usage example of intercepting string length in PHP

高洛峰
高洛峰Original
2017-01-14 15:10:551142browse

The example of this article describes the usage of intercepting the length of string 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.

I hope this article will be helpful to everyone in PHP programming.

For more related articles about string length interception usage examples in PHP, please pay attention to 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