PHP strpos check against many

前端 未结 3 1779
野性不改
野性不改 2021-01-27 06:39

I am looking to use strpos to check for many chars in a string, for example:

I would like to separately check for the chars :,!, a

3条回答
  •  暖寄归人
    2021-01-27 07:19

    Use preg_match

    preg_match("/[:!&]/", $string) !== 1;
    

    Example:

    var_dump(preg_match("/[:!&]/", "this is !a test string"));
    > int(1)
    var_dump(preg_match("/[:!&]/", "this is a test string"));
    > int(0)
    

    preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.

提交回复
热议问题