Guest User

Untitled

a guest
Sep 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. public static function parse_url($url)
  2. {
  3. $result = array();
  4.  
  5. // Build arrays of values we need to decode before parsing
  6. $entities = array('%3A', '%40', '%26', '%3D', '%2F', '%3F', '%23', '%5B', '%5D');
  7. $replacements = array(":", "@", "&", "=", "/", "?", "#", "[", "]");
  8.  
  9. // Create encoded URL with special URL characters decoded so it can be parsed
  10. // All other characters will be encoded
  11. $encodedURL = str_replace($entities, $replacements, urlencode($url));
  12.  
  13. // Parse the encoded URL
  14. $encodedParts = parse_url($encodedURL);
  15.  
  16. // Now, decode each value of the resulting array
  17. foreach ($encodedParts as $key => $value)
  18. {
  19. $result[$key] = urldecode($value);
  20. }
  21.  
  22. return $result;
  23. }
Add Comment
Please, Sign In to add comment