split url in php code example
Example 1: how to split url in php
<?php
$url = 'http://www.example.com/news?q=string&f=true&id=1233&sort=true';
$values = parse_url($url);
$host = explode('.',$values['host']);
echo $host[1];
?>
Example 2: part of url php
//https://www.google.com/search?key=1234
$url = $_SERVER['REQUEST_URI'];
$url_components = parse_url($url);
parse_str($url_components['query'], $params);
$key = $params['key'];
// key=1234