Requests_IRI::parse_iri()

最后更新于:2021-11-26 03:58:34

Requests_IRI::parse_iri( string$iri)

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

参数

$iri

(string) (Required)

响应

(array)

源文件

文件: gc-includes/Requests/IRI.php

	protected function parse_iri($iri) {
		$iri = trim($iri, "x20x09x0Ax0Cx0D");
		$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;
	}