Organizational Research By

Surprising Reserch Topic

Experts Most Trusted 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
4 views



Related Hot Questions



Government Jobs Opening


...