you may want to use preg_replace_callback() for this. For the sake of clarity, let's say you have the following TWO (separate/independent) input strings
a;b\";\"c;d';'ef\;g
a;b\";'\"c;d';'ef\;g
what results do you expect? Do you have a sample of an actual/realistic input string?
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
try:
$str=<<<STR
multipart/alternative; boundary="001636284f500b21f90494114b4d"
multipart/alternative; boundary='f01636284f500b;21f90494114b4f'
multipart/alternative; boundary="001636284f;500b21f90494114b4d"
foo; fa="001636284f5"\; fy="00b21f90494114b4d"
STR;
$str=preg_replace('#(\x22|\x27)([^;]*)(?<!\x5C)(;)(.*?)\1#','$1$2'.chr(7).chr(92).';$4$1',$str);
$m=preg_split('#(?<![\x5C]);#',$str);
foreach($m as $i=>$v)
{
$m[$i]=str_replace(chr(7).chr(92).';',';',$v);
}
//this shows the result
print_r($m);
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244