博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
substr_count_PHP substr_count()函数与示例
阅读量:2529 次
发布时间:2019-05-11

本文共 1374 字,大约阅读时间需要 4 分钟。

substr_count

PHP substr_count()函数 (PHP substr_count() Function)

substr_count() function is a string function in PHP, it is used to find the total number of occurrences of a substring in the given string.

substr_count()函数是PHP中的字符串函数,用于查找给定字符串中子字符串出现的总数。

Syntax:

句法:

substr_count(string, substring, [offset], [length]);

Here,

这里,

  • string is the main string in which we have to perform the search for the substring.

    string是我们必须在其中搜索子 字符串的主要字符串。

  • substring is the part of the string that we have search in the string.

    substring是我们在字符串中搜索的字符串的一部分 。

  • offset is an optional parameter, it defines the start index – from where you want to search the string. Its default value is 0.

    offset是一个可选参数,它定义了起始索引,即您要从中搜索字符串的位置。 默认值为0。

  • length is also an optional parameter, it defines length of the search i.e. search operation will start from offset and finishes with offset+length position.

    length也是一个可选参数,它定义了搜索的长度,即搜索操作将从offset开始,并以offset + length位置结束。

Examples:

例子:

Input:     str = "Hello friends how are your friends?";    substring = "friends";    Output:    2    Input:    str = "Hello friends how are your friends?";    substring = "Hello";    Output:    1    Input:    str = "Hello friends how are your friends?";    substring = "Hi";    Output:    0

PHP code:

PHP代码:

Output

输出量

friends found 2 times.Hi found 0 times.friends found 1 times.friends found 0 times.

翻译自:

substr_count

转载地址:http://gnvzd.baihongyu.com/

你可能感兴趣的文章
原生js大总结二
查看>>
PHP基础
查看>>
UVa 11488 超级前缀集合(Trie的应用)
查看>>
Django 翻译与 LANGUAGE_CODE
查看>>
[转]iOS教程:SQLite的创建数据库,表,插入查看数据
查看>>
【转载】OmniGraffle (一)从工具栏开始
查看>>
初识ionic
查看>>
java 中打印调用栈
查看>>
开发 笔记
查看>>
数据挖掘算法比赛 - 简单经验总结
查看>>
生成商户订单号/退款单号
查看>>
使用Android OpenGL ES 2.0绘图之六:响应触摸事件
查看>>
我们过去几年做对了哪些事
查看>>
Java Bigdecimal使用
查看>>
SQL注入之绕过WAF和Filter
查看>>
jquery validate使用方法
查看>>
DataNode 工作机制
查看>>
windows系统下安装MySQL
查看>>
实验二+070+胡阳洋
查看>>
Linux IPC实践(3) --具名FIFO
查看>>