php - How can I explode a string into an array by space, but preserve quoted words? -


given string abc "def ghi", how can return array:

[0] => abc [1] => def ghi 

other examples:

abc "def ghi"   =>   ['abc','def ghi'] abc def         =>   ['abc','def'] 

str_getcsv()

$str = 'abc "def ghi"'; $arr = str_getcsv($str, ' ', '"'); print_r($arr); 

returns:

array (     [0] => abc     [1] => def ghi ) 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -