【发布时间】:2015-05-22 06:25:49
【问题描述】:
我想在一个字符串中找到多个单词的位置。
例如:
$str="Learning php is fun!";
我想获得 php 和 fun 的位置。
我的预期输出是:-
1) Php这个词出现在第9位
2) fun这个词排在第16位。
这是我尝试过的代码,但它不适用于多个单词。
<?Php
$arr_words=array("fun","php");
$str="Learning php is fun!";
$x=strpos($str,$arr_words);
echo The word $words[1] was found on $x[1] position";
echo The word $words[2] was found on $x[2] position";
有人知道它有什么问题以及如何解决吗?
非常感谢任何帮助。
谢谢!
【问题讨论】: