PHP字符串爆炸与正则表达式?

时间:2013-05-17 13:12:38

标签: php regex explode

PHP String使用正则表达式进行爆炸 示例数据:

"A" 100000  "M" "C" "J"         "JOHNSON TRENCHING" 238910

预期结果:

array (
  0 => 'A',
  1 => '100000',
  2 => 'M',
  3 => 'C',
  4 => '',
  5 => '',
  6 => 'JOHNSON TRENCHING',
  7 => '238910'
);

1 个答案:

答案 0 :(得分:1)

试试这个

$string = '"A" 100000 "M" "C" "J" "JOHNSON TRENCHING" 238910';
$string = preg_match_all('/(\"[a-zA-Z0-9\s]+\")|[0-9]+/', $string, $matches);

print_r($matches);