转载自: http://www.newsmth.net/nForum/article/Algorithm/49305
用PHP实现一下吧.
<?php
function get_start($l, $s) {
$a = array();
foreach($l as $k=>$v) {
$a[$k] = getCharpos2($s, $v);
}
return $a;
}
function getCharpos2($str, $char){
$j = 0;
$arr = array();
$count = substr_count($str, $char);
for($i = 0; $i < $count; $i++){
$j = strpos($str, $char, $j);
$arr[] = $j;
$j = $j+1;
}
return $arr;
}
$l = array("fooo","barr","wing","ding","wing");
$s = "lingmindraboofooowingdingbarrwingmonkeypoundcake";
$leng = strlen($l[0]); // 字符串固定长度
$arr = array();
for($i=0;$i<strlen($s);$i++) {
$tmpstr = substr($s, $i, $leng);
$tmpkey = array_search($tmpstr, $l);
//var_dump($tmpkey);
}
function get_key($str, $arr) {
}