php函数stripos高级用法 检查字符串是否以某个字符串开头或者结尾

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

(0)
彬彬笔记彬彬笔记
上一篇 2023年2月14日
下一篇 2023年2月19日

相关推荐

发表回复

登录后才能评论
蜀ICP备14017386号-13