<?php
    $testStr='ถังบำบัดน้ำเสีย 20,000 ลิตร';//ไม่นับสระบน-ล่าง=22, นับทั้งหมด=27
    $string='ถังบำบัดน้ำเสีย 20,000 ลิตร';//ไม่นับสระบน-ล่าง=22, นับทั้งหมด=27
    $testStr1='123456789012345678901234567890123456789012345678901234567890';
    echo $len=strlen($testStr).'<br>';
    echo substr($testStr,0,100).'<br>';
    echo $len=strlen($testStr1).'<br>';
    echo substr($testStr1,0,100).'<br>';

    echo iconv_strlen($testStr).'<br>';
    echo iconv_strlen($testStr,'utf-8').'<br>';

// Convert a string to an array with multibyte string
function getMBStrSplit($string, $split_length = 1){
	mb_internal_encoding('UTF-8');
	mb_regex_encoding('UTF-8'); 
	
	$split_length = ($split_length <= 0) ? 1 : $split_length;
	$mb_strlen = mb_strlen($string, 'utf-8');
	$array = array();
	$i = 0; 
	while($i < $mb_strlen)
	{
		$array[] = mb_substr($string, $i, $split_length);
		$i = $i+$split_length;
	}
	return $array;
}

    // Get string length for Character Thai
    function getStrLenTH($string)
    {
	$array = getMBStrSplit($string);
	$count = 0;	
	foreach($array as $value)
	{
		$ascii = ord(iconv("UTF-8", "TIS-620", $value ));
		
		if( !( $ascii == 209 ||  ($ascii >= 212 && $ascii <= 218 ) || ($ascii >= 231 && $ascii <= 238 )) )
		{
			$count += 1;
		}
	}
	return $count;
    }
    echo getStrLenTH($string);
?>    