I am trying to identify if a string has any words between double quotes using preg_match_all
, however it's duplicating results and the first result has two sets of double quotes either side, where as the string being searched only has the one set.
Here is my code:
$str = 'Test start. "Test match this". Test end.';
$groups = array();
preg_match_all('/"([^"]+)"/', $str, $groups);
var_dump($groups);
And the var dump produces:
array(2) {
[0]=>
array(1) {
[0]=>
string(17) ""Test match this""
}
[1]=>
array(1) {
[0]=>
string(15) "Test match this"
}
}
As you can see the first array is wrong, why is preg_match_all
returning this?
var_dump
here? – Conservativevar_dump
. I didn't realise thatpreg_match_all
recorded with and without the capture, and that it wasvar_dump
adding quotes around the strings. The two lots of double quotes is what I thought was wrong. – Spa