3v4l.org

run code in 300+ PHP versions simultaneously
<?php $urls = [ 'http://evil.com?example.org/foo/bar', 'http://evil.com?example.org/foo/bar?baz#quux', 'http://evil.com?example.org?baz#quux', 'http://evil.com?example.org#quux', ]; foreach ( $urls as $url ) { $bits = parse_url( $url ); if ( isset( $bits['host'] ) && strpos( $bits['host'], '?' ) !== false ) { list( $host, $query ) = explode( '?', $bits['host'], 2 ); $bits['host'] = $host; $bits['query'] = $query . ( isset( $bits['path'] ) ? $bits['path'] : '' ) . ( isset( $bits['query'] ) ? '?' . $bits['query'] : '' ); unset( $bits['path'] ); } var_dump( $bits ); }

preferences:
68.11 ms | 402 KiB | 5 Q