php 换行 空格分割处理
<?php
function parse_specification($specification){
$rt=array();
$lines=array_filter(preg_split("/[\n]/",$specification));
foreach($lines as $line){
$fields=array_filter(preg_split("/[\s]+/",$line));
if(count($fields)>1){
$rt[]=array('k'=>array_shift($fields),'v'=>join(' ',$fields));
}
}
return $rt;
}
$specification = trim($product['specification']);
if(!empty($specification)){
$specification = parse_specification($specification);
}
?>
posted on 2015-12-02 09:57 andydaopeng 阅读(1534) 评论(0) 收藏 举报
浙公网安备 33010602011771号