1
<?php

$str = "asd,ad";
if(preg_match(",",$str)) { 
    echo "ok";
}

?

It outputs me

No ending delimiter ',' found in....

?>

2 Answers2

2

your pattern can be replaced to strpos instead

if(strpos($str, ",")!==false)
{
   echo "ok";
}
ajreal
  • 46,720
  • 11
  • 89
  • 119
1

You are missing delimitters, try this:

$str = "asd,ad";
if(preg_match("/,/",$str)) { 
    echo "ok";
}

To find out more instances, you may want to use preg_match_all function too.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578