What's the most efficient test of whether a PHP string ends with another string?

后端 未结 13 662
时光说笑
时光说笑 2020-11-29 18:53

The standard PHP way to test whether a string $str ends with a substring $test is:

$endsWith = substr( $str, -strlen( $test ) ) ==          


        
相关标签:
13条回答
  • 2020-11-29 19:35

    easiest way to check it via regular expression

    for example to check if the mail given is gmail:

    echo (preg_match("/@gmail\.com$/","example-email@gmail.com"))?'true':'false';
    
    0 讨论(0)
提交回复
热议问题