Requests_IRI::to_uri() WordPress Method

The Requests_IRI::to_uri() function takes an IRI (Internationalized Resource Identifier) and converts it to a URI (Uniform Resource Identifier).

Requests_IRI::to_uri( $string ) #

Convert an IRI to a URI (or parts thereof)


Parameters

(string|bool)(Required)IRI to convert (or false from get_iri)


Top ↑

Return

(string|false) URI if IRI is valid, false otherwise.


Top ↑

Source

File: wp-includes/Requests/IRI.php

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

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

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

		return $string;
	}

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.