Dev Hub Dev Hub - 6 months ago 20
PHP Question

STRiSTR not matching data from string

Its strange to me, why

stristr
not matching data? It always print
not found


$data = 'Saturday';

$find = 'sat,sun';

if(stristr($data, $find))
echo 'found';
else
echo 'not found';

Answer

stristr() find the first occurrence of a string Case-insensitive. You can also use preg_match instead.

Try

<?php
   $find = "sat,sun";
   $data = 'Sat';

   if (preg_match("/\b".$data."\b/i", $find, $match))
      print "Match found!";
   else
        print "not match";
?>