不灭的焱

革命尚未成功,同志仍须努力

作者:php-note.com  发布于:2020-04-14 13:59  分类:PHP基础  编辑
// 变量:
$s1 = "dotcoo world!";
$s2 = "dotcoo";
$s3 = "hello dotcoo";

// PHP判断字符串开头:
var_dump(substr($s1, 0, strlen($s2)) === $s2);
var_dump(strpos($s1, $s2) === 0);
var_dump(strncmp($s1, $s2, strlen($s2)) === 0);
var_dump(substr_compare($s1, $s2, 0, strlen($s2)) === 0);
var_dump(substr($s1, 0, strlen($s2)) === $s2);

// PHP判断字符串结尾:
var_dump(substr_compare($s3, $s2, -strlen($s2)) === 0);