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>";
?>

更多相关文章

  1. 将DOMDocument中的特定元素导出为字符串
  2. PHP实现字符串转换成查询语句
  3. mysql 判断null 和 空字符串
  4. mysql主从同步报slave_sql_running:no的解决方案
  5. mysql如何判断一个字符串是否包含另外一个字符串?
  6. mySQL:按给定的ID字符串排序ID? (为分层数据构建面包屑)
  7. 用PHP比较PHP中的字符串
  8. win7下Django的MySql安装,问题解决方案
  9. 如何用C++向MYSQL插入UNICODE字符串?

随机推荐

  1. Android Studio第六期 - 横向GridView
  2. android的k歌
  3. Android--遍历SQLite数据库下的所有表名
  4. EditText
  5. Android--取得布局中指定控件的宽高
  6. Android取得系统信息和分辨率内存信息
  7. 删除android ScrollView边界阴影方法
  8. Android ListView二三事
  9. Android_linux下android platforms下载地
  10. android之wifi移植全过程(一)