Substring Compare PHP


Substring Compare PHP

为什么这段代码不回显0

$email = "test@example.com";
$ending = "com";
$email = preg_replace('/[^A-Za-z0-9'-]/', '', $email);
echo substr_compare($email, $ending, strlen($ending)-strlen($email), strlen($ending));

我期待0,每个文档

如果您想检查是否以"com"结尾

读一读:PHP中的startsWith()和endsWith()函数


但是如果你只想调试结果:

尝试将整数转换为字符串以正确输出结果。

echo (string)substr_compare($email, $ending, strlen($ending)-strlen($email), strlen($ending));

或做的事:

$result = substr_compare($email, $ending, strlen($ending)-strlen($email), strlen($ending));
var_dump($result); // or echo (string)$result;