PHP explode terms in to array, retain quoted text as single array item

前端 未结 4 2038
粉色の甜心
粉色の甜心 2021-01-17 00:11

I have the following string from a form...

Opera \"adds cross-platform hardware\" \"kicks butt\" -hippies

In general I\'ve simpl

4条回答
  •  盖世英雄少女心
    2021-01-17 01:09

    You could use a preg_match_all(...):

    $text = 'Opera "adds cross-platform hardware" "kicks butt" -hippies';
    preg_match_all('/"(?:\\\\.|[^\\\\"])*"|\S+/', $text, $matches);
    print_r($matches);
    

提交回复
热议问题