Skip to content

Instantly share code, notes, and snippets.

@fayqLs
Created October 23, 2024 19:57
Show Gist options
  • Save fayqLs/ae6d783a8a3bbab9b067124a56ff6e0c to your computer and use it in GitHub Desktop.
Save fayqLs/ae6d783a8a3bbab9b067124a56ff6e0c to your computer and use it in GitHub Desktop.
CAPTURAR PARTES DA URL
<?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