Php function _ PHP Tutorial for intercepting strings of a specific length

Source: Internet
Author: User
A php function used to intercept a string of a specific length. * 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 *, it is used to intercept the php (as the mainstream development language) function of a string of a specific length and 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

Return $ str;
} // End function

?>

Php (as the mainstream development language) function used to intercept strings of a specific length and process Chinese characters at the same time. * return the truncated string. if the string length is less than or equal...

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.