What is the best way to parse a URL string into separate parts for database storage in PHP?
When storing URLs in a database, it is often useful to parse the URL into separate parts such as the scheme, host, path, query parameters, etc. This can make it easier to retrieve and manipulate specific parts of the URL later on. One way to achieve this in PHP is by using the `parse_url()` function, which breaks down a URL string into its components.
$url = "https://www.example.com/path/to/page?query=123";
$parsedUrl = parse_url($url);
$scheme = $parsedUrl['scheme'];
$host = $parsedUrl['host'];
$path = $parsedUrl['path'];
$query = $parsedUrl['query'];
// Now you can store these individual parts in your database