-
-
Save fayqLs/ae6d783a8a3bbab9b067124a56ff6e0c to your computer and use it in GitHub Desktop.
CAPTURAR PARTES DA URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'https://www.google.com.br/'; | |
public static function extrairNome($url) | |
{ | |
$host = parse_url($url, PHP_URL_HOST); | |
$partes = explode('.', $host); | |
return $partes[0]; | |
} | |
# EXEMPLO DE USO: | |
$partes = self::extrairNome($url); | |
$nome = $partes[1]; | |
# $partes[0] = www | |
# $partes[1] = google |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment