Changeset 6314
- Timestamp:
- 11/05/2007 05:13:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r6182 r6314 95 95 96 96 function seems_utf8($Str) { # by bmorel at ssi dot fr 97 for ($i=0; $i<strlen($Str); $i++) { 97 $length = strlen($Str); 98 for ($i=0; $i < $length; $i++) { 98 99 if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb 99 100 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb … … 104 105 else return false; # Does not match any model 105 106 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? 106 if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))107 if ((++$i == $length) || ((ord($Str[$i]) & 0xC0) != 0x80)) 107 108 return false; 108 109 } … … 133 134 $values = array(); 134 135 $num_octets = 1; 135 136 for ($i = 0; $i < strlen( $utf8_string ); $i++ ) { 136 $unicode_length = 0; 137 138 $string_length = strlen( $utf8_string ); 139 for ($i = 0; $i < $string_length; $i++ ) { 137 140 138 141 $value = ord( $utf8_string[ $i ] ); 139 142 140 143 if ( $value < 128 ) { 141 if ( $length && ( strlen($unicode) + 1 >$length ) )144 if ( $length && ( $unicode_length >= $length ) ) 142 145 break; 143 146 $unicode .= chr($value); 147 $unicode_length++; 144 148 } else { 145 149 if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; … … 147 151 $values[] = $value; 148 152 149 if ( $length && ( (strlen($unicode) + ($num_octets * 3)) > $length ))153 if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length ) 150 154 break; 151 155 if ( count( $values ) == $num_octets ) { 152 156 if ($num_octets == 3) { 153 157 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); 158 $unicode_length += 9; 154 159 } else { 155 160 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); 161 $unicode_length += 6; 156 162 } 157 163
Note: See TracChangeset
for help on using the changeset viewer.