PHP function for intercepting strings of specific length_PHP tutorial

WBOY
Release: 2016-07-13 17:32:58
Original
1056 people have browsed it

* PHP (as the current mainstream development language) function used to intercept strings of a specific length, while processing Chinese characters.
* Returns the intercepted string; if the string length is less than or If equal to parameter $str_len, the original string is returned.
*
* @access(favorite for small websites) public
* @param string $str The string that needs to be intercepted.
* @param integer $str_len The length of the intercepted string.
* @param string $str_append When the interception operation occurs, the string added at the end of the intercepted 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); > } //end if

return $str;
} //end function

?>

http://www.bkjia.com/PHPjc/508667.html

truehttp: //www.bkjia.com/PHPjc/508667.htmlTechArticle* PHP (as the current mainstream development language) function for intercepting strings of a specific length, and processing at the same time Chinese characters. * Returns the intercepted string; if the string length is less than or equal to...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template