I'm trying to split my url and have them in two variables.
For Example:
url = https://example.com/page@01
I want to be able split this url into two and create two variable.
$part_1 = example.com;
$part_2 = page@01
Thank you.
I'm trying to split my url and have them in two variables.
For Example:
url = https://example.com/page@01
I want to be able split this url into two and create two variable.
$part_1 = example.com;
$part_2 = page@01
Thank you.
Use parse_url
function to split url into components.
$data = parse_url('https://example.com/page@01');
print_r($data);
Output:
Array ( [scheme] => https [host] => example.com [path] => /page@01 )
You can also use explode()
$a = "https://example.com/page@01";
$b = explode('/', $a);
$part_1 = $b[2];
$part_2 = $b[3];
print_r($part_1);
echo '<br>';
print_r($part_2);
You can use $_SERVER
, with which you can retrieve various information regarding script headers, paths, and locations, including the URL, by following the example below:
URL = https://example.com/page@01
$_SERVER['REQUEST_URI'] = /page@01
$_SERVER['HTTP_HOST'] = example.com
Reference: $_SERVER