[solved]Keeping everything between double quotes
Posted: Thu Apr 13, 2006 10:04 pm
Hi guyz,
Ive tried to get the regex to work so that only text between double quotes is splitted with the preg_split function, but it's final expression i'm having trouble with. Here's my code:
Output: Array ( [0] => just [1] => hopefully [2] => some1 will get it to "work! )
So my problem is that the last piece of text is splitted into the array while I only want "just" and "hopefully" in array.
Hopefully someone can help me on this last part of the regex expression..
Thanks..
Ive tried to get the regex to work so that only text between double quotes is splitted with the preg_split function, but it's final expression i'm having trouble with. Here's my code:
Code: Select all
$test = 'This is "just" a test. But "hopefully" some1 will get it to "work!';
$string1=preg_split('/(\".*?\")+(.*?)/',$test,-1,PREG_SPLIT_NO_EMPTY);
$pattern = '/.*?"(.*?)"/';
$string= preg_split ($pattern, $test, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);So my problem is that the last piece of text is splitted into the array while I only want "just" and "hopefully" in array.
Hopefully someone can help me on this last part of the regex expression..
Thanks..