3v4l.org

run code in 300+ PHP versions simultaneously
<?php $val = "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"; var_dump($val); list($name, $value) = explode('=', $val, 2); $regexPattern = sprintf( '/^ %1$s # match a quote at the start of the value ( # capturing sub-pattern used (?: # we do not need to capture this [^%1$s\\\\] # any character other than a quote or backslash |\\\\\\\\ # or two backslashes together |\\\\%1$s # or an escaped quote e.g \" )* # as many characters that match the previous rules ) # end of the capturing sub-pattern %1$s # and the closing quote .*$ # and discard any string after the closing quote /mx', $quote ); $value = preg_replace($regexPattern, '$1', $value); $value = str_replace("\\$quote", $quote, $value); $value = str_replace('\\\\', '\\', $value); var_dump($value);

preferences:
45.51 ms | 402 KiB | 5 Q