标签:style blog color io os ar for sp div
function getNext( $str ){ $ret = array(0=>0); for( $j =1; $j < strlen($str); $j++ ){ $_s = substr( $str, 0, $j+1 ); $_ln = strlen($_s); $ret[$j] = 0; for( $i = 1; $i< $_ln; $i++ ){ $start = substr($_s, 0 ,$i); $end = substr($_s, -$i); if($start == $end){ $ret[$j] = $i; } } } return $ret; } function _strpos( $str, $sstr, $p = 0 ){ $rt = false; //返回结果 $l1 = strlen($sstr); $l2 = strlen($str); if($l1 > $l2) return $rt; $i = $p; $j = 0; $next = getNext($sstr); while( $i< $l2 && $j < $l1 ){ echo "i:".$i." iv:".$str[$i]." j:".$j." jv:".$sstr[$j]."<br>"; if( $j == 0 || $sstr[$j] == $str[$i] ){ ++$i; ++$j; }else{ $j = $next[$j-1]; } } if( $j == $l1 ) return $i - $l1; else return $rt; } var_dump( _strpos( "aabaaab" ,"aaa" ) );
标签:style blog color io os ar for sp div
原文地址:http://www.cnblogs.com/glory-jzx/p/4026976.html