<?php
/*
PHP strpos() 函数
从第一个字符开始查询
*/
function findstr ($str2,$str1) {
/*strpos — Find the position of the first occurrence of a substring in a string
Description
在字符串中第一次出现的位置(0开始),没有输出-1。例如:
echo findstr("sswwd","wd");
输出会是3.
*/
for ($i=0 ; $i<strlen($str2); $i++) {
if( $str1[0]==$str2[$i] ){
for ($k=$j=$i,$m=0;$m<strlen($str1);$j++,$m++){
if( $str1[$m]!=$str2[$j] ) {
$k=-1;
}
}
if ($k==$i){
return $k;
}
}
}
return -1;
}
echo findstr("sswwd","wd");
?>
<?php
/*
PHP strpos() 函数
自定义开始查询的位置
*/
function findstr ($str2,$str1,$start) {
/*strpos — Find the position of the first occurrence of a substring in a string
Description
在字符串中第一次出现的位置(0开始)。例如:
echo findstr("sswwd","wd");
输出会是3.
*/
for ($i=$start ; $i<strlen($str2); $i++) {
if( $str1[0]==$str2[$i] ){
for ($k=$j=$i,$m=0;$m<strlen($str1);$j++,$m++){
if( $str1[$m]!=$str2[$j] ) {
$k=-1;
}
}
if ($k==$i){
return $k;
}
}
}
return -1;
}
echo findstr("sswqdwss三十d","wqd","1");
echo findstr("sswqdwss三十d","wqd","4");
//echo $_SERVER['SCRIPT_FILENAME'];
?>
自写PHP strpos() 函数 查找字符串在另一字符串中第一次出现的位置。&amp;lt;?php/*PHP strpos() 函数*/function findstr ($str2,$str1) {/*strpos — Find the position of the first occurrence of a substring in a stringDescription在...