PHP forward slash match

前端 未结 2 1292
孤城傲影
孤城傲影 2021-01-15 04:36

How I can check if some string contains forward slash in PHP?

相关标签:
2条回答
  • 2021-01-15 05:14

    Check for occurences with strpos()

    if (strpos($string, '/') !== FALSE) // Found
    

    Returns the position as an integer. If needle is not found, strpos() will return boolean FALSE.

    This is faster than a regular expression, and most other methods, because it stops checking at the first occurrence.

    0 讨论(0)
  • 2021-01-15 05:23

    It is very simple:

    preg_match ('~/~', $string);
    
    0 讨论(0)
提交回复
热议问题