Organizational Research By

Surprising Reserch Topic

php explode the string but treat words in quotes as a single word


php explode the string but treat words in quotes as a single word  using -'php,quotes,explode,str-replace'

How can I explode the following string:

Lorem ipsum "dolor sit amet" consectetur "adipiscing elit" dolor


into

array("Lorem", "ipsum", "dolor sit amet", "consectetur", "adipiscing elit", "dolor")


So that the text in quotation is treated as a single word.

Here's what I have for now:

$mytext = "Lorem ipsum %22dolor sit amet%22 consectetur %22adipiscing elit%22 dolor"
$noquotes = str_replace("%22", "", $mytext");
$newarray = explode(" ", $noquotes);


but my code divides each word into an array. How do I make words inside quotation marks treated as one word?
    

asked Sep 30, 2015 by sujata naik
0 votes
5 views



Related Hot Questions

5 Answers

0 votes
NULL
answered Sep 30, 2015 by rajeevr642
0 votes
NULL
answered Sep 30, 2015 by ukohale
0 votes
NULL
answered Sep 30, 2015 by mannumits1
0 votes
NULL
answered Sep 30, 2015 by gauravg.gwl
0 votes
NULL
answered Sep 30, 2015 by nimisha.jagtap

...