Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




utf8_uri_encode [ WordPress Function ]

utf8_uri_encode ( $utf8_string, $length = 0 )
Parameters:
  • (string) $utf8_string
  • (int) $length Max length of the string
Returns:
  • (string) String with Unicode encoded for URI.
Defined at:



Encode the Unicode values to be used in the URI.

Source


<?php
function utf8_uri_encode$utf8_string$length ) {
    
$unicode '';
    
$values = array();
    
$num_octets 1;
    
$unicode_length 0;

    
$string_length strlen$utf8_string );
    for (
$i 0$i $string_length$i++ ) {

        
$value ord$utf8_string$i ] );

        if ( 
$value 128 ) {
            if ( 
$length && ( $unicode_length >= $length ) )
                break;
            
$unicode .= chr($value);
            
$unicode_length++;
        } else {
            if ( 
count$values ) == $num_octets = ( $value 224 ) ? 3;

            
$values[] = $value;

            if ( 
$length && ( $unicode_length + ($num_octets 3) ) > $length )
                break;
            if ( 
count$values ) == $num_octets ) {
                if (
$num_octets == 3) {
                    
$unicode .= '%' dechex($values[0]) . '%' dechex($values[1]) . '%' dechex($values[2]);
                    
$unicode_length += 9;
                } else {
                    
$unicode .= '%' dechex($values[0]) . '%' dechex($values[1]);
                    
$unicode_length += 6;
                }

                
$values = array();
                
$num_octets 1;
            }
        }
    }

    return 
$unicode;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics