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);
	        		}
        		?>

 

你可能感兴趣的:(php 换行 空格分割处理)