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);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
string(70) "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'" Warning: Undefined variable $quote in /in/sHv0k on line 21 Warning: Undefined variable $quote in /in/sHv0k on line 24 Warning: Undefined variable $quote in /in/sHv0k on line 24 Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /in/sHv0k on line 24 string(66) "'a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(70) "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'" Warning: Undefined variable $quote in /in/sHv0k on line 21 Warning: Undefined variable $quote in /in/sHv0k on line 24 Warning: Undefined variable $quote in /in/sHv0k on line 24 Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /in/sHv0k on line 24 string(66) "'a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"
Output for 8.0.0 - 8.0.30
string(70) "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'" Warning: Undefined variable $quote in /in/sHv0k on line 21 Warning: Undefined variable $quote in /in/sHv0k on line 24 Warning: Undefined variable $quote in /in/sHv0k on line 24 string(66) "'a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"
Output for 7.0.20, 7.1.5 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
string(70) "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'" Notice: Undefined variable: quote in /in/sHv0k on line 21 Notice: Undefined variable: quote in /in/sHv0k on line 24 Notice: Undefined variable: quote in /in/sHv0k on line 24 string(66) "'a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"
Output for 7.3.32 - 7.3.33
string(70) "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'" string(66) "'a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"
Output for 7.0.0 - 7.0.6, 7.1.0
string(70) "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'" Notice: Undefined variable: quote in /in/sHv0k on line 20 Notice: Undefined variable: quote in /in/sHv0k on line 24 Notice: Undefined variable: quote in /in/sHv0k on line 24 string(66) "'a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
string(70) "LOL='a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'" Notice: Undefined variable: quote in /in/sHv0k on line 22 Notice: Undefined variable: quote in /in/sHv0k on line 24 Notice: Undefined variable: quote in /in/sHv0k on line 24 string(66) "'a,`=/0+4Aq|8,l@DsAK,4Y~t}BWHozy;w`O!dFnLi]/1TF9(jb.*4MR9l2iD5rh^'"

preferences:
137.22 ms | 402 KiB | 182 Q