3v4l.org

run code in 300+ PHP versions simultaneously
<?php $urls = [ 'www.example.com/myurl.html?unwantedthngs#hastag', 'www.example.com/myurl.html' ]; foreach ($urls as $url) { var_export(['strtok: ', strtok($url, '?')]); echo "\n"; var_export(['strstr/true: ', strstr($url, '?', true)]); // not reliable echo "\n"; var_export(['explode/2: ', explode('?', $url, 2)[0]]); // limit alls func to stop searching after first encounter echo "\n"; var_export(['substr/strrpos: ', substr($url, 0, strrpos( $url, "?"))]); // not reliable; still not with strpos() echo "\n---\n"; }

preferences:
39.79 ms | 402 KiB | 5 Q