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 阅读(1520) 评论(0) 编辑 收藏 举报