您好,欢迎访问一九零五行业门户网

在PHP中检查一个字符串是否以给定的单词开头

create a function to check whether a string begins with the specified string or not. the function should return true on success or false on failure.
the following is the syntax −
begnwith(str, begnstr)
consider the following parameters in it to check −
str − the string to be tested
begnstr − the text to be searched in the beginning of the specified string.
examplethe following is an example −
live demo
<?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!
以上就是在php中检查一个字符串是否以给定的单词开头的详细内容。
其它类似信息

推荐信息