Requests_IRI::to_uri() protected WP 1.0
Convert an IRI to a URI (or parts thereof)
{} It's a method of the class: Requests_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( $string );
- IRI(string/true/false) (required)
- to convert (or false from {@see get_iri})
Code of Requests_IRI::to_uri() Requests IRI::to uri WP 5.6
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;
}