字符串的逗号是无规则如:111,222,,,333,444,,又如:,,,111,222,,,333,444又如:111,222,,,333,444又如:,,,1881,,,,414,,,,,又如:,,,111,222,,,333,又如:,,,111,其中数也不规定长度的
å符串çéå·æ¯æ è§å
追ç$str="111,222,,,333,,444,,,,666";
$arr_str=explode(',',$str);
$arr_str=array_filter($arr_str);
foreach($arr_str as $val){
$ret[]=$val;
}
$new_str=implode(','$ret);
print_r($new_str);
...111,222,,,333,444,,处理之后返回 111,222,333,44
str="111,222,,,333,,444,,,666";sttr=str_replace(',,,',','$str);sttr=str_replace(',,,',','$str);
...111,222,,,333,444,, 处理之后返回 111,222,333,444
用正则提取数字不就行了?var str="111,222,,,333,444,, ";str=str.match(\/\\d+\/g).join(",");alert(str);