2017-03-07 49 views
-3

如果我定义了一个简单的单词变量,我将如何计算并以简单的方式输出单词中的元音数量?如何检查单词中的元音

我已经搜索并找到了许多类似的方法来做到这一点,但大多数似乎比必要的更复杂,但我正在寻找最简单的解决方案。

我的字变量将是这样的:

$word = "Apple" 

我只想显示的总的情况下,E,I,O,U

预先感谢您。

+2

创建一个包含所有元音的地图,在这个词的每一个字母迭代,如果当前字母是vowels_map增加一个计数器,返回柜台。 – SuperTetelman

+0

http://stackoverflow.com/questions/29450399/counting-number-of-vowels-in-a-string-with-javascript –

+0

http://stackoverflow.com/questions/7465304/simple-way-to-count -the元音-IN-A-字符串中的PHP – mrahmat

回答

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

我希望它会帮助你