在PHP中计算字符串中的元音的简单方法? [英] Simple way to count the vowels in a string in PHP?

查看:66
本文介绍了在PHP中计算字符串中的元音的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我定义一个简单的字符串变量,我将如何以最简单的方式计算和输出字符串中的元音数量?

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."

我只想显示a,e,i,o,u的全部实例.预先谢谢你.

I just want to display the total instances of a,e,i,o,u. Thank you in advance.

推荐答案

这是一个简单的解决方案:

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

这篇关于在PHP中计算字符串中的元音的简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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