advanced patterns with PHP's `filter_var` when validating URLs with specific characters
I've searched everywhere and can't find a clear answer. I can't seem to get I can't seem to get I'm experimenting with I'm working with an scenario when using `filter_var` to validate URLs in PHP 8.1. It seems to unexpected result on URLs that contain certain special characters, like `#` or `%`. For instance, when I try to validate the following URLs: ```php $urls = [ 'http://example.com/path?query=1', 'http://example.com/path#section', 'http://example.com/path%20with%20spaces', 'http://example.com/path?query=1¶m=%23section' ]; foreach ($urls as $url) { if (filter_var($url, FILTER_VALIDATE_URL) === false) { echo "$url is not a valid URL\n"; } else { echo "$url is valid\n"; } } ``` The first and the last URLs pass the validation check without any issues, but the second one (`http://example.com/path#section`) is incorrectly marked as invalid. According to the [PHP documentation](https://www.php.net/manual/en/filter.filters.validate.php), the `FILTER_VALIDATE_URL` should allow fragment identifiers (the part after `#`), but I am not seeing this in action. I have also tried using `rawurlencode` to encode the URLs before validation, but it didn't help with the scenario. I'm not sure if this is a bug or if I am missing something in how `filter_var` works with URLs that have fragments. Any insights or workarounds would be greatly appreciated. What's the correct way to implement this? Could someone point me to the right documentation? I'm working on a microservice that needs to handle this. Any suggestions would be helpful.