Also useful for breaking down expressions - for example parsing SQL: values ('this', fn("that,)()", 4))
$sep = strcspn ($list, "'\"`"); // Start of quoted string
$list = substr ($list, $sep);
$find = substr ($list, 0, 1);
while (($sep = strpos ($list, $find, $sep+1)) > 0 && substr ($list, $sep-1, 1) == '\\')
{}
// $sep now spans the entire string, regardless of embedded quotes
Once the strings have been removed, an expression can then be parsed for commas and brackets without worrying about them:
while ($out != '')
{
$sep = strcspn ($list, "(),"); // Next seperator
...
}