# 123abcd345adsd 转换为 123:abcd 345:adsd
$str = '123abcd345adsd1';
$len = strlen( $str );
$i = 0;
$new = '';
while( 1 ){
# 判断截取的是什么类型的
if( is_numeric( $str[$i] ) ){
$type = 1;
}else{
$type = 2;
}
if( isset( $str[$i+1] ) ){
if( $type == 1 && !is_numeric( $str[$i+1] ) ){
$new .= $str[$i].':';
}else if( $type == 1 && is_numeric( $str[$i+1] ) ){
$new .= $str[$i];
}
if( $type == 2 && is_numeric( $str[$i+1] ) ){
$new .= $str[$i]."<br/>";
}else if( $type == 2 && !is_numeric( $str[$i+1] ) ){
$new .= $str[$i];
}
$i ++;
if( $i > $len ){
break;
}
}else{
if( $type == 1 ){
$new .= $str[$i].':';
}else{
$new .=$str[$i].'<br/>';
}
break;
}
}
echo '<hr/>';
echo $new;
数字和字母不同分割符分割
最新推荐文章于 2022-03-28 16:13:23 发布