PHP: comparing URIs which differ in percent-encoding

ovarPhaccaclere

New Member
In PHP, I want to compare two relative URLs for equality. The catch: URLs may differ in percent-encoding, e.g.
  • \[code\]/dir/file+file\[/code\] vs. \[code\]/dir/file%20file\[/code\]
  • \[code\]/dir/file(file)\[/code\] vs. \[code\]/dir/file%28file%29\[/code\]
  • \[code\]/dir/file%5bfile\[/code\] vs. \[code\]/dir/file%5Bfile\[/code\]
According to RFC 3986, servers should treat these URIs identically. But if I use \[code\]==\[/code\] to compare, I'll end up with a mismatch.So I'm looking for a PHP function which will accepts two strings and returns \[code\]TRUE\[/code\] if they represent the same URI (dicounting encoded/decoded variants of the same char, upper-case/lower-case hex digits in encoded chars, and \[code\]+\[/code\] vs. \[code\]%20\[/code\] for spaces), and \[code\]FALSE\[/code\] if they're different.I know in advance that only ASCII chars are in these strings-- no unicode.
 
Back
Top