Search code examples
phppreg-match-allstrpos

Multiple strpos possible?


I'm trying to see if my string contains { and : and } if so returns true, but I'm missing something here.

$string = "{12345:98765}";

if(strpos($string,'{*:*}')== true) {

echo "string is good";

}

Ideas?


Solution

  • How about:

    if (preg_match('/\{.*?:.*?\}/', $string)) {
        echo 'string is good.';
    }
    

    Where:

    /
      \{    : openning curly brace (must be escaped, it' a special char in regex)
      .*?   : 0 or more any char (non greeddy)
      :     : semicolon
      .*?   : 0 or more any char (non greeddy)
      \}    : closing curly brace (must be escaped, it' a special char in regex)
    /