What are the potential pitfalls of using preg_split to extract values from a URL in PHP?

Using preg_split to extract values from a URL in PHP can be problematic because it relies on regular expressions, which can be complex and error-prone. Additionally, if the URL structure changes, the regular expression may need to be updated accordingly. It is generally better to use built-in PHP functions like parse_url to extract specific parts of a URL.

$url = "https://www.example.com/page?id=123";
$parsed_url = parse_url($url);
$query_string = $parsed_url['query'];
parse_str($query_string, $params);
$id = $params['id'];
echo $id; // Output: 123