PHP strlen() 函数计算字符串的长度

| | Comments (0)



程序的编辑大凡原理机制都差不多,掌握好一门程序语言,应该先了解框架结构,接着是一个个函数、语法等的作用,最后才能融会贯通,写出达到自己要求的一套程序来,在写程序的过程,尽量做到编写没有错误的程序而不是忽略它。

PHP计算字符串长度,包括计算英文、GBK、UTF-8多种字符集下PHP如何计算字符串长度,其他的一些语言、软件中都有自带的函数,那么PHP岂能没有,所以strlen()是PHP自带的计算英文字符串的函数。


让我们算出字符串 "Hello world!" 的长度:

<?php
echo strlen("Hello world!");
?>

以上代码的输出:

12

字符串的长度信息常常用在循环或其他函数中,因为那时确定字符串何时结束是很重要的(例如,在循环中,我们需要在字符串中的最后一个字符之后结束循环)。


更多php学习资料请访问:http://www.w3school.com.cn/php/


单点日志:http://spoint.babyshoot.cn

Leave a comment

Archives

Ads by google

Pages

Powered by Movable Type 4.24-en

About this Entry

This page contains a single entry by 单点日志 published on April 10, 2011 8:34 PM.

如何才能获得成功 was the previous entry in this blog.

Google Doodle:默片时代的喜剧之王-查理·卓别林 122 周年诞辰 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.