1. 使用 stripos
函数来检查字符串是否以某个字符串开头:
<?php
$string = "Hello world";
$needle = "Hello";
if (stripos($string, $needle) === 0) {
echo $string . " starts with " . $needle;
} else {
echo $string . " does not start with " . $needle;
}
// Output:
// Hello world starts with Hello
?>
2. 使用 stripos
函数来检查字符串是否以某个字符串结尾:
<?php
$string = "Hello world";
$needle = "world";
if (stripos($string, $needle) === strlen($string) - strlen($needle)) {
echo $string . " ends with " . $needle;
} else {
echo $string . " does not end with " . $needle;
}
// Output:
// Hello world ends with world
?>
这些示例只是 stripos
函数的一部分高级用法,实际上,该函数还具有很多其他功能,您可以根据需要进一步学习和了解。希望本篇文章对您有所帮助。
发布者:彬彬笔记,转载请注明出处:https://www.binbinbiji.com/php/3061.html