用PHP计算字符串中元音的简单方法?
16lz
2021-01-22
If I define a simple string variable, how would I count and output the number of vowels in the string in the simplest possible way?
如果我定义一个简单的字符串变量,我将如何以最简单的方式计算和输出字符串中的元音数?
I have searched and found a number of similar ways to do so, but most seem more complex than necessary. They are all functional and maybe the complexity IS necessary, but I am looking for the simplest solution possible.
我搜索并发现了许多类似的方法,但大多数似乎都比必要的复杂得多。它们都是功能性的,也许复杂性是必要的,但是我正在寻找可能的最简单的解决方案。
My string variable would be something like:
我的字符串变量应该是:
$someString = "This is some text with some more text and even more text."
I just want to display the total instances of a,e,i,o,u. Thank you in advance.
我只想显示a e I o u的所有实例。提前谢谢你。
10 个解决方案
#1
8
Here's an easy solution:
这是一个简单的解决方案:
<?php
$string = "This is some text with some more text and even more text.";
echo "There are <strong>".preg_match_all('/[aeiou]/i',$string,$matches)." vowels</strong> in the string <strong>".$string."</strong>";
?>
更多相关文章
- 将DOMDocument中的特定元素导出为字符串
- PHP实现字符串转换成查询语句
- mysql 判断null 和 空字符串
- mysql主从同步报slave_sql_running:no的解决方案
- mysql如何判断一个字符串是否包含另外一个字符串?
- mySQL:按给定的ID字符串排序ID? (为分层数据构建面包屑)
- 用PHP比较PHP中的字符串
- win7下Django的MySql安装,问题解决方案
- 如何用C++向MYSQL插入UNICODE字符串?