创建一个函数来检查字符串是否以指定的字符串开头。如果成功,该函数应返回TRUE;如果失败,则应返回FALSE。
以下是语法-
begnWith(str, begnStr)
考虑其中的以下参数进行检查-
str-要测试的字符串
begnStr-在指定字符串的开头要搜索的文本。
以下是一个例子-
<?php
function begnWith($str, $begnString) {
$len = strlen($begnString);
return (substr($str, 0, $len) = = = $begnString);
}
if(begnWith("pqrstuvwxyz","p"))
echo "True! It begins with p!";
else
echo "False! It isn't beginning with p!";
?>输出结果
以下是输出-
True! It begins with p!