[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Uri Package 4 * 5 * @copyright Copyright (C) 2005 - 2022 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Uri; 10 11 /** 12 * Uri Helper 13 * 14 * This class provides a UTF-8 safe version of parse_url(). 15 * 16 * @since 1.0 17 */ 18 class UriHelper 19 { 20 /** 21 * Does a UTF-8 safe version of PHP parse_url function 22 * 23 * @param string $url URL to parse 24 * @param integer $component Retrieve just a specific URL component 25 * 26 * @return array|boolean Associative array or false if badly formed URL. 27 * 28 * @link https://www.php.net/manual/en/function.parse-url.php 29 * @since 1.0 30 */ 31 public static function parse_url($url, $component = -1) 32 { 33 $result = []; 34 35 // If no UTF-8 chars in the url just parse it using php native parse_url which is faster. 36 if (utf8_decode($url) === $url) 37 { 38 return parse_url($url, $component); 39 } 40 41 // URL with UTF-8 chars in the url. 42 43 // Build the reserved uri encoded characters map. 44 $reservedUriCharactersMap = [ 45 '%21' => '!', 46 '%2A' => '*', 47 '%27' => "'", 48 '%28' => '(', 49 '%29' => ')', 50 '%3B' => ';', 51 '%3A' => ':', 52 '%40' => '@', 53 '%26' => '&', 54 '%3D' => '=', 55 '%24' => '$', 56 '%2C' => ',', 57 '%2F' => '/', 58 '%3F' => '?', 59 '%23' => '#', 60 '%5B' => '[', 61 '%5D' => ']', 62 ]; 63 64 // Encode the URL (so UTF-8 chars are encoded), revert the encoding in the reserved uri characters and parse the url. 65 $parts = parse_url(strtr(urlencode($url), $reservedUriCharactersMap), $component); 66 67 // With a well formed url decode the url (so UTF-8 chars are decoded). 68 return $parts ? array_map('urldecode', $parts) : $parts; 69 } 70 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |