WpOrg\Requests
Iri::to_uri
Convert an IRI to a URI (or parts thereof)
Method of the class: Iri{}
No Hooks.
Returns
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() Iri::to uri code WP 7.0
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;
}