如何计算字符串中子字符串的出现次数? [英] How to count the number of occurrences of a substring in a string?

查看:86
本文介绍了如何计算字符串中子字符串的出现次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何在不使用string函数的情况下查找给定字符串中子字符串的出现次数.例如字符串是"当男人得到母鸡时",而我期望的结果是子字符串""在该字符串中出现了 4 次.给定的字符串.

Anybody can tell me about how to find the number of occurrence of substring in the given string without using the string function . for example the string is "when the men get the hen" and the result i expected is the substring 'he' occur 4 times in the given string.

推荐答案

substr_count('when the men get the hen', 'he');

http://php.net/manual/zh/function.substr- count.php

这篇关于如何计算字符串中子字符串的出现次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆