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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -