Created
August 6, 2021 16:19
-
-
Save dinizgb/242087f66f2d859effffadbaf22fe00b to your computer and use it in GitHub Desktop.
get-url-parts-in-php
This file contains 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 | |
/* | |
Script: Get URL Parts in PHP | |
Author: Gabriel Diniz | |
*/ | |
$url = 'https://www.example.com/pathname?queryname=googley'; | |
//FULL PARSING | |
var_dump(parse_url($url)); | |
echo "<hr>"; | |
//PARTIAL PARSING | |
var_dump(parse_url($url, PHP_URL_SCHEME)); | |
var_dump(parse_url($url, PHP_URL_HOST)); | |
var_dump(parse_url($url, PHP_URL_PATH)); | |
var_dump(parse_url($url, PHP_URL_QUERY)); | |
echo "<hr>"; | |
//PARTS TO ECHO | |
$host = parse_url($url, PHP_URL_HOST); | |
$path = parse_url($url, PHP_URL_PATH); | |
$query = parse_url($url, PHP_URL_QUERY); | |
echo "HOST: $host"; | |
echo "<br>"; | |
echo "PATH: $path"; | |
echo "<br>"; | |
echo "QUERY: $query"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment