3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getSocialUser( $uri ) { $parsed = parse_url( $uri ); $path = $parsed[ 'path' ];// Usuário, mas com alguns caracteres que devem ser filtrados $host = str_replace( 'www.', '', $parsed[ 'host' ] );// Retiramos o 'www.' $host_name = explode( '.', $host )[ 0 ];// Separamos pelo '.' e pegamos a primeira parte $allowed_hosts = [ 'twitter', 'facebook', 'instagram' ];// Hosts permitidos if ( !in_array( $host_name, $allowed_hosts ) ) return false;// Se não estiver entre os permitidos, retorne falso (ou exception) return strtok( ltrim( $path, '/' ), '/' ); } $url1 = 'https://www.facebook.com/gilberto.gil'; $url2 = 'http://instagram.com/gilberto.gil/posts'; $url3 = 'https://twitter.com/gilberto.gil?parametro_qualquer=123'; $url4 = 'https://google.com/gilberto.gil?parametro_qualquer=123'; echo ( getSocialUser( $url1 ) ?: 'Inválido' ) . "\n"; echo ( getSocialUser( $url2 ) ?: 'Inválido' ) . "\n"; echo ( getSocialUser( $url3 ) ?: 'Inválido' ) . "\n"; echo ( getSocialUser( $url4 ) ?: 'Inválido' ) . "\n";
Output for 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
gilberto.gil gilberto.gil gilberto.gil Inválido
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 gilberto.gil gilberto.gil gilberto.gil Inválido

preferences:
140.16 ms | 402 KiB | 154 Q