La fonction Php parse_url()

Description La fonction parse_url() en Php analyse une URL et retourne ses composants sous forme de tableau associatif.

Depuis la version 5.1.2 de php, la fonction permet de ne récupérer qu'un composant de l'URL.

Composants :
- PHP_URL_SCHEME : type de l'url (http, ftp, ...)
- PHP_URL_HOST : host (nom de domaine, ip, ...)
- PHP_URL_PORT : port
- PHP_URL_USER : nom d'utilisateur
- PHP_URL_PASS : mot de passe
- PHP_URL_PATH : chemin
- PHP_URL_QUERY : variables de l'url
- PHP_URL_FRAGMENT
Publicité
Solution <?php
$url = 'http://www.click-internet.fr/index.php?cki=Situation-Clients';

echo "Tableau associatif :<br />";
print_r(parse_url($url))."<br /><br />";

echo "host de l'url :<br />";
echo parse_url($url, PHP_URL_HOST);

// Informations retournées par les deux affichages
?>
Tableau associatif :
Array
(
[scheme] => http
[host] => www.click-internet.fr
[path] => /index.php
[query] => cki=Situation-Clients
)

host de l'url :
www.click-internet.fr
Notez la solution
1.7/5 (207 votes)
Partagez cette question
Questions similaires
Mots clés php, fonction, parse_url, host, path, chemin, variables
Derniére modification le 03/10/08 à 13:23