PHP strcspn() 函数
PHP 教程
· 2019-01-30 07:43:00
实例
输出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符数:
<?php
echo strcspn("Hello world!","w");
?>
echo strcspn("Hello world!","w");
?>
定义和用法
strcspn() 函数返回在找到任何指定的字符之前,在字符串查找的字符数(包括空格)。
提示: Use the strspn() function to the number of characters found in the string that contains only characters from a specified character list.
注释: This function is binary-safe.
语法
strcspn(string,char,start,length)
| 参数 | 描述 |
|---|---|
| string | 必需。规定要搜索的字符串。 |
| char | 必需。规定要查找的字符。 |
| start | 可选。规定开始查找的位置。 |
| length | 可选。规定字符串的长度(搜索多少字符)。 |
技术细节
| 返回值: | 返回在找到任何指定的字符之前,在字符串查找的字符数。 |
|---|---|
| PHP 版本: | 4+ |
| 更新日志: | 在 PHP 4.3 中,新增了 start 和 length 参数。 |
更多实例
实例 1
使用所有的参数来输出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符数:
<?php
echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6.
?>
echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6.
?>
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
"笨办法"学Python
肖 (Zed A.Shaw) / 王巍巍 / 人民邮电出版社 / 2014-11-1 / CNY 49.00
本书是一本Python入门书籍,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用。这本书以习题的方式引导读者一步一步学习编程,从简单的打印一直讲到完整项目的实现,让初学者从基础的编程技术入手,最终体验到软件开发的基本过程。 本书结构非常简单,共包括52个习题,其中26个覆盖了输入/输出、变量和函数三个主题,另外26个覆盖了一些比较高级的话题,如条件判断、循环、类和对象、代码测......一起来看看 《"笨办法"学Python》 这本书的介绍吧!