Php function used to extract strings of a specific length
Source: Internet
Author: User
* The php function used to intercept strings of a specific length (as a mainstream development language) and process Chinese characters at the same time. * returns the truncated string. if the string length is less than or equal to the value of & #36; str_len, the original string is returned. ** @ Access (a favorite of small websites) & nbsp; public * @ param & nbsp; stringSynt * is a function used to intercept php strings of a specific length (as the mainstream development language, process Chinese characters at the same time.
* Returns the truncated string. if the string length is less than or equal to $ str_len, the original string is returned.
*
* @ Access (a favorite of small websites) public
* @ Param string $ str the string to be truncated.
* @ Param integer $ str_len refers to the length of the string intercepted.
* @ Param string $ str_append: the string added at the last side of the truncated string. the default value is
Function my_substr ($ str, $ str_len, $ str_append = ......)
{
If (strlen ($ str)> $ str_len ){
$ Str_len-= strlen ($ str_append );
For ($ I = $ str_len, $ j = 0; $ I> = 0, ord ($ str [$ I-1])> 128; $ I --, $ j ++ );;
$ Str = ($ j % 2! = 0)
? Substr ($ str, 0, $ str_len-1 ).
: Substr ($ str, 0, $ str_len );
$ Str. = $ str_append;
} // End if
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service