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

WBOY
Release: 2016-06-02 11:33:44
Original
1192 people have browsed it

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>
Copy after login

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

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!