Welcome folks today in this blog post we will be checking if a string contains a specific world or not using strpos() method
using php 7
. All the full source code of the application is shown below.
Get Started
In order to get started you need to make an index.php
file and copy paste the following code
index.php
<?php
$str='Codespeedy Codes faster and also in efficient manner';//source string
$s='Codes';//finding string
$i = $m = $c =$flag=0;
while ( !empty($str[$c]))
{
if ( $str[$m] == $s[$i] )
{
$i++;
$m++;
if ( empty($s[$i])) //Find occurance
{
echo $s.' is present in '.($c+1).' location<br>';
$flag=1;
$i=0;
$c=$m;
}
}
else //... mismatch
{
$c++;
$m = $c;
$i=0;
}
}
if($flag==0)
echo $s.' is not present';
?>