search
Homephp教程php手册php 字符串长度函数

php 字符串长度函数

Jun 13, 2016 am 11:17 AM
phpstrlenfunctionexiststringyeshavetestoflengthdefault

php 字符串长度函数,在php测试字符串长度的函数有二个,一个是strlen,另一个是mb_strlen前一个默认是支持,后一个需要开启一个插件,下面我们来介绍一下二个函数的区别与应用方法。  

php教程 字符串长度函数,在php测试字符串长度的函数有二个,一个是strlen,另一个是mb_strlen前一个默认是支持,后一个需要开启一个插件,下面我们来介绍一下二个函数的区别与应用方法。

php strlen() 函数
定义和用法
strlen() 函数返回字符串的长度。

语法
strlen(string)参数 描述
string 必需。规定要检查的字符串。

echo strlen("www.bkjia.com!"); //13
echo strlen("中国人!");//6 strlen得到的值是汉字个数的2倍
?>

尝试将php_mbstring.dll复制到%windows%目录下

$str = '懂php的都知道strlen与mb_strlen是求字符串长度的函数';
echo strlen($str)'.
'.mb_strlen($str,'utf-8');
?>

运行上述代码,返回值如下:
66
34

懂php的都知道strlen与mb_strlen是求字符串长度的函数,但是对于一些初学者来说,如果不看手册,也许不太清楚其中的区别。
先看这样一段代码吧(先决条件是:字符编码为utf-8):


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),