Hi guys
Does anyone know how I could split this string by the "
" character but somehow ignore any "
" characters within quotes?
An example of the string to split would be;
test@testtesttest.com test 1,000
tester@testtesttest.com tester “2,000
test”
Any help would be much appreciated
Thanks
Crabby
hmmm doesn’t seem to work, it still splits “test”
Array (
[0] => test@testtesttest.com test 1,000
[1] => tester@testtesttest.com tester "2,000
[2] => test
test@testtesttest.com test 1,000\
tester@testtesttest.com tester "2,000\
test"\
Thanks Anthony,
I’ll check it out, man I need to learn regex!
Hmm, maybe something like…
<?php
$subject = "foo\
bar\\"\
\\"foo\
bar";
$elements = preg_split(
'~(?<!")\
(?!")~',
$subject
);
echo '<pre>', print_r($elements, true) ;
/*
Array
(
[0] => foo
[1] => bar"
"foo
[2] => bar
)
*/
?>
Splits on a new line, but not if the new line is quoted.