3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Remove a query string parameter from an URL. * * @param string $url * @param string $varname * * @return string */ function removeQueryStringParameter($url, $varname) { $parsedUrl = parse_url($url); $query = array(); if (isset($parsedUrl['query'])) { parse_str($parsedUrl['query'], $query); unset($query[$varname]); } $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; $query = !empty($query) ? '?'. http_build_query($query) : ''; return $parsedUrl['scheme']. '://'. $parsedUrl['host']. $path. $query; } $urls = array( 'http://www.example.com?test=test', 'http://www.example.com?bar=foo&test=test2&foo2=dooh', 'http://www.example.com', 'http://www.example.com?foo=bar', 'http://www.example.com/test/no-empty-path/?foo=bar&test=test5', 'https://www.example.com/test/test.test?test=test6', ); foreach ($urls as $url) { echo $url.PHP_EOL; echo removeQueryStringParameter($url, 'test'). PHP_EOL. PHP_EOL; }
Output for 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
http://www.example.com?test=test http://www.example.com http://www.example.com?bar=foo&test=test2&foo2=dooh http://www.example.com?bar=foo&foo2=dooh http://www.example.com http://www.example.com http://www.example.com?foo=bar http://www.example.com?foo=bar http://www.example.com/test/no-empty-path/?foo=bar&test=test5 http://www.example.com/test/no-empty-path/?foo=bar https://www.example.com/test/test.test?test=test6 https://www.example.com/test/test.test
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 http://www.example.com?test=test http://www.example.com http://www.example.com?bar=foo&test=test2&foo2=dooh http://www.example.com?bar=foo&foo2=dooh http://www.example.com http://www.example.com http://www.example.com?foo=bar http://www.example.com?foo=bar http://www.example.com/test/no-empty-path/?foo=bar&test=test5 http://www.example.com/test/no-empty-path/?foo=bar https://www.example.com/test/test.test?test=test6 https://www.example.com/test/test.test
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?test=testPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.comPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?bar=foo&test=test2&foo2=doohPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.com?bar=foo&foo2=doohPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.comPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.comPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?foo=barPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.com?foo=barPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com/test/no-empty-path/?foo=bar&test=test5PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.com/test/no-empty-path/?foo=barPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 https://www.example.com/test/test.test?test=test6PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 https://www.example.com/test/test.testPHP_EOLPHP_EOL
Output for 4.4.5 - 4.4.9
http://www.example.com?test=test http://www.example.com http://www.example.com?bar=foo&test=test2&foo2=dooh Fatal error: Call to undefined function: http_build_query() in /in/LjrEr on line 22
Process exited with code 255.
Output for 4.3.10 - 4.3.11, 4.4.0 - 4.4.4
http://www.example.com?test=test http://www.example.com http://www.example.com?bar=foo&test=test2&foo2=dooh Fatal error: Call to undefined function: http_build_query() in /in/LjrEr on line 22
Process exited with code 255.
Output for 4.3.2 - 4.3.9
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?test=testPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.comPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?bar=foo&test=test2&foo2=doohPHP_EOL Fatal error: Call to undefined function: http_build_query() in /in/LjrEr on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?test=testPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.com?test=testPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?bar=foo&test=test2&foo2=doohPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.com?bar=foo&test=test2&foo2=doohPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.comPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.comPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com?foo=barPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 38 http://www.example.com?foo=barPHP_EOLPHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LjrEr on line 37 http://www.example.com/test/no-empty-path/?foo=bar&test=test5PHP_EOL Fatal error: Call to undefined function: http_build_query() in /in/LjrEr on line 22

preferences:
300.99 ms | 405 KiB | 465 Q