use Zend\Uri\Uri; $uri = Uri::factory('http://example.com'); if ($uri->isValid()) { echo $uri->getHost(); // outputs 'example.com' }
use Zend\Uri\Http; $uri = new Http('http://example.com/path/to/file.php?key=value#fragment'); $uri->setHost('new.example.com'); echo $uri; // outputs 'http://new.example.com/path/to/file.php?key=value#fragment'This example creates a new Http object with a URI string containing a path, query string, and fragment. It then sets the hostname to 'new.example.com' using the setHost() method and outputs the modified URI using the object's __toString() method. Package Library: This package is part of the Zend Framework library, which is a collection of components and modules for PHP web development.