WpOrg\Requests

Iri::to_uri()protectedWP 1.0

Convert an IRI to a URI (or parts thereof)

Method of the class: Iri{}

No Hooks.

Return

String|false. URI if IRI is valid, false otherwise.

Usage

// protected - for code of main (parent) or child class
$result = $this->to_uri( $iri );
$iri(string|true|false) (required)
IRI to convert (or false from \WpOrg\Requests\Iri::get_iri())

Iri::to_uri() code WP 6.6.2

protected function to_uri($iri) {
	if (!is_string($iri)) {
		return false;
	}

	static $non_ascii;
	if (!$non_ascii) {
		$non_ascii = implode('', range("\x80", "\xFF"));
	}

	$position = 0;
	$strlen = strlen($iri);
	while (($position += strcspn($iri, $non_ascii, $position)) < $strlen) {
		$iri = substr_replace($iri, sprintf('%%%02X', ord($iri[$position])), $position, 1);
		$position += 3;
		$strlen += 2;
	}

	return $iri;
}