PHP | parse_url() Function Example
Hi Friends,
This example is PHP | parse_url() Function Example.
The parse_url() function is an inbuilt functionin PHP which is used to return the components of a URL by parsing it.
It parse an URL and return an associative array which contains its various components.
Let's start following example.
Syntax:
parse_url( $url, $component = -1 )
Example 1:
<?php
// Declare a variable and initialize it with URL
$url = '/php/#basics';
// Use parse_url() function to parse the URL
var_dump(parse_url($url));
var_dump(parse_url($url, PHP_URL_SCHEME));
?>
Output:
array(4) {
["scheme"]=>
string(5) "https"
["host"]=>
string(16) "nicesnippets.com"
["path"]=>
string(5) "/php/"
["fragment"]=>
string(6) "basics"
}
string(5) "https"
Example 2:
<?php
// Declare a variable and initialize it with URL
$url = '//www.nicesnippets.com/path?php=PHP';
// Use parse_url() function to
// parse the URL
var_dump(parse_url($url));
?>
Output:
array(3) {
["host"]=>
string(20) "www.nicesnippets.com"
["path"]=>
string(5) "/path"
["query"]=>
string(7) "php=PHP"
}
I hope it can help you....
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example