<?php
$str = '"1234 567" 123 3456 "3123 23" 432 32 423 "432 43" 432';
$arr = preg_split("/^\"|(\" )|( \")| (?=[ \d]+$)|( (?=[ \d]*( \")))/", $str);
print_r($arr);
?>
$str = '"1234 567" 123 3456 "3123 23" 432 32 423 "432 43" 432';
$arr = preg_split("/^\"|(\" )|( \")| (?=[ \d]+$)|( (?=[ \d]*( \")))/", $str);
print_r($arr);
?>
你可以用stream函数库轻松的解决此类问题,手册中就有现成的例子stream_wrapper_register("csvstr", "csvstream") ;
$str = '"1234 567" 123 3456 "3123 23"';
$fp = fopen("csvstr://str", "r+");
print_r(fgetcsv($fp,100," ",'"')); csvstream类定义
class csvstream {
var $position;
var $varname;
function stream_open($path, $mode, $options, &$opened_path){
$url = parse_url($path);
$this->varname = $url['host'] ;
$this->position = 0;
return true;
}
function stream_read($count){
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
function stream_eof(){
return $this->position >= strlen($GLOBALS[$this->varname]);
}
function stream_tell(){
return $this->position;
}
}