21,886
社区成员
发帖
与我相关
我的任务
分享
function dealStr($str,&$result=array()){
$findComma = strpos($str,',');
if (!$findComma) {
$result[]=$str;
unset($str);
}else{
//获取字符串长度
$len = strlen($str);
//获取逗号后面的字符
$endOfComma = strstr($str,',');
$CommaLen = strlen($endOfComma);
$findrednik = strpos($endOfComma,';');
//截取','第一次出现位置之前的字符
$str1 = substr($str,0,$findComma);
$str2 = $str1.substr($endOfComma,$findrednik,$CommaLen);//结果1→3;2→3;3→1;4→3;5→0;6→1;7→1,2;9→3;14→0 1 2 9_1
$str3 = substr($str,0,$findComma-1);
$str4 = $str3.substr($str,$findComma+1,$len);//结果1→3;2→3;3→1;4→3;5→1,2;6→1;7→1,2;9→3;14→0 1 2 9_1
unset ($str);
dealStr($str2,$result);
dealStr($str4,$result);
}
return $result;
}
$str = '1→0,1,2;2→0,1,2;3→0,1,2;4→0,1,2;5→0,1,2;6→0,1,2;7→0,1,2;9→0,1,2;14→0,1,2 1 2 9_1';
$msg = dealStr($str);
print_r($msg);