Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

seems_utf8()

Description

Looks for particular patterns to attempt to determine if the provided string is in UTF8 format

Parameters

ColumnTypeDefaultDescription
$str string

Return

boolean True if it's possibly UTF8

Location

include/language_functions.php lines 519 to 549

Definition

 
function seems_utf8($str)
{
    
$length strlen($str);

    for (
$i 0$i $length$i++) {
        
$c ord($str[$i]);

        if (
$c 0x80) {
            
$n 0# 0bbbbbbb
        
} elseif (($c 0xE0) == 0xC0) {
            
$n 1# 110bbbbb
        
} elseif (($c 0xF0) == 0xE0) {
            
$n 2# 1110bbbb
        
} elseif (($c 0xF8) == 0xF0) {
            
$n 3# 11110bbb
        
} elseif (($c 0xFC) == 0xF8) {
            
$n 4# 111110bb
        
} elseif (($c 0xFE) == 0xFC) {
            
$n 5# 1111110b
        
} else {
            return 
false# Does not match any model
        
}

        for (
$j 0$j $n$j++) { # n bytes matching 10bbbbbb follow ?
            
if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) {
                return 
false;
            }
        }
    }
    return 
true;
}

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 28th October 2024 11:15 Europe/London time.