Home  >  Article  >  Backend Development  >  php-这个计算字符串长度的函数的原理?

php-这个计算字符串长度的函数的原理?

WBOY
WBOYOriginal
2016-06-02 11:33:441193browse

php

<code> function str_len($str){    $length = strlen(preg_replace('/[\x00-\x7F]/', '', $str));    if ($length)    {        return strlen($str) - $length + intval($length / 3) * 2;    }    else    {        return strlen($str);    }}</code>

strlen(preg_replace('/[\x00-\x7F]/', '', $str));这条语句的作用是什么?
strlen($str) - $length + intval($length / 3) * 2;后面这里 intval($length / 3) * 2;的作用是什么?
为什么要这么做?

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