I want to find the position of a few words in a line.
Example:
$str="Learning php is fun!";
I want to get the position of php and fun .
And my expected result will be: -
1) The word Php was found in the 9th position.
2) The word fun was found in 16th position.
Here is the code I tried, but it does not work for a few words.
<?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";
Does anyone know what is wrong with him, and how to fix it?
Any help would be very helpful.
Thank!
source
share