Requests_IRI::parse_iri() WordPress Method

The Requests_IRI::parse_iri() method is used to parse an IRI and return an associative array of its parts. The parts that are returned are: scheme, authority, path, query, and fragment. This method is useful for when you need to parse an IRI but do not need the full functionality of the Requests_URL class.

Requests_IRI::parse_iri( string $iri ) #

Parse an IRI into scheme/authority/path/query/fragment segments


Parameters

$iri

(string)(Required)


Top ↑

Return

(array)


Top ↑

Source

File: wp-includes/Requests/IRI.php

	protected function parse_iri($iri) {
		$iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
		$has_match = preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match);
		if (!$has_match) {
			throw new Requests_Exception('Cannot parse supplied IRI', 'iri.cannot_parse', $iri);
		}

		if ($match[1] === '') {
			$match['scheme'] = null;
		}
		if (!isset($match[3]) || $match[3] === '') {
			$match['authority'] = null;
		}
		if (!isset($match[5])) {
			$match['path'] = '';
		}
		if (!isset($match[6]) || $match[6] === '') {
			$match['query'] = null;
		}
		if (!isset($match[8]) || $match[8] === '') {
			$match['fragment'] = null;
		}
		return $match;
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.