Reputation: 269
I have this regular exception:
(?:([^\:]*)\:\/\/)?(?:([^\:\@]*)(?:\:([^\@]*))?\@)?(?:([^\/\:]*)\.(?=[^\.\/\:]*\.[^\.\/\:]*))?([^\.\/\:]*)(?:\.([^\/\.\:]*))?(?:\:([0-9]*))?(\/[^\?#]*(?=.*?\/)\/)?([^\?#]*)?(?:\?([^#]*))?(?:#(.*))?
1) If parse url: http://test.ru/long/path/file.ext?queryparam=123&more=234 - its OK
2) If parse url: ftp://admin:[email protected]/long/path/file.ext - its OK
3) BUT, if in GET parameter exist [AT] (@), it is not work correct!
Example: http://test.ru/long/path/file.ext?queryparam=123&[email protected]
PS. Regular exception find on stackoverflow, but don't remember the topic.:(
Upvotes: 0
Views: 174
Reputation: 15045
If you are trying to parse a URL, regex is not the way. PHP has a built in function called parse_url() that will break the URL up into its segments to easily access. More efficient and way less code. In addition you can further break up the query segment with parse_str() Lastly, if you want to break up the path you can use pathinfo() as well. PHP has all these readily available, you just need to start using them.
Upvotes: 2
Reputation: 28712
That is correct that it fails because it's a malformed url.
The url should read
http://test.ru/long/path/file.ext?queryparam=123&mail=test%40domain.com
instead of the malformed [email protected].
the javascript function encodeURIComponent('@');
is your friend :D
Upvotes: 3