strops () :- Show us the position of the string…
It takes 3 argument . 1st :- the string in which we want to search in, 2nd :- character which we want to find… , 3rd :- OPTIONAL offset MEANS WHERE TO START… By default it is zero…
< ? php
$find1=”ar”;
$find1_len=strlen($find1);
$string1=”Harshida Parmar, IT Engi. IT“;
Echo strpos($string1,$find1);
? >
So when we run the page it will show use the position of “ar”
But as you can see in out string variable $string1… “ar” come more than once… Above return the first instance found after that it is not return another “ar ” position
So we need to go through the loop
< ? php
$offset=0;
$find1=”ar”;
$find1_len=strlen($find1);
$string1=”Harshida Parmar, IT Engi. IT“;
While($str_pos= strops($string1,$find,$offset)) {
echo “FOUND OUT :- >”.$str_pos;
$offset=$str_pos + $find1_len;
} ? >
Now it will give the out put .. where ”ar” found… Shows us the position of “ar”.
No comments:
Post a Comment