Home  >  Article  >  Backend Development  >  What should I do if php exceeds the character length?

What should I do if php exceeds the character length?

藏色散人
藏色散人Original
2021-11-29 09:17:452698browse

Solution to php exceeding the character length: 1. Create a PHP sample file; 2. Display characters of the specified length through the "function cutSubstr($str,$len=30){...}" method String, and when the characters exceed the length, the tail is filled with ellipsis and displayed.

What should I do if php exceeds the character length?

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3.

What should I do if php exceeds the character length?

php displays a string of specified length. If the length exceeds the length, fill in the tail with an ellipsis (...) and display

/**
* php显示指定长度的字符串,超出长度以省略号(...)填补尾部显示
* @ str 字符串
* @ len 指定长度
**/
function cutSubstr($str,$len=30){
 if (strlen($str)>$len) {
$str=substr($str,0,$len) . '...';
 }
 return $str;
}

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php exceeds the character length?. 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