= 3) { $end = func_get_arg(2); return join("",array_slice($ar[0],$start,$end)); } else { return join("",array_slice($ar[0],$start)); } } function pre_substr($string,$start,$length) { global $chkcharset; if($chkcharset=="UTF-8") { if(!defined('UTF8_NOMBSTRING')&&function_exists('mb_substr')) { return mb_substr($string,$start,$length,'utf-8'); } else { return utf8_substr($string,$start,$length); } } if($chkcharset!="UTF-8") { return substr($string,$start,$length); } } if(isset($_GET['text'])) { echo pre_substr($_GET['text'],0,6); } // author: Scott Michael Reynen "scott@randomchaos.com" // url: http://www.randomchaos.com/document.php?source=php_and_unicode function utf8_strpos($haystack, $needle,$offset=0) { if(!defined('UTF8_NOMBSTRING')&&function_exists('mb_strpos')) { return mb_strpos($haystack,$needle,$offset,'utf-8'); } $haystack = utf8_to_unicode($haystack); $needle = utf8_to_unicode($needle); $position = $offset; $found = false; while( (! $found ) && ( $position < count( $haystack ) ) ) { if ( $needle[0] == $haystack[$position] ) { for ($i = 1; $i < count( $needle ); $i++ ) { if ( $needle[$i] != $haystack[ $position + $i ] ) break; } // for if ( $i == count( $needle ) ) { $found = true; $position--; } // if } // if $position++; } // while return ( $found == true ) ? $position : false; } // strpos_unicode // author: Scott Michael Reynen "scott@randomchaos.com" // url: http://www.randomchaos.com/document.php?source=php_and_unicode function utf8_to_unicode( $str ) { $unicode = array(); $values = array(); $lookingFor = 1; for ($i = 0; $i < strlen( $str ); $i++ ) { $thisValue = ord( $str[ $i ] ); if ( $thisValue < 128 ) $unicode[] = $thisValue; else { if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3; $values[] = $thisValue; if ( count( $values ) == $lookingFor ) { $number = ( $lookingFor == 3 ) ? ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ): ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 ); $unicode[] = $number; $values = array(); $lookingFor = 1; } // if } // if } // for return $unicode; } // utf8_to_unicode // author: Scott Michael Reynen "scott@randomchaos.com" // url: http://www.randomchaos.com/document.php?source=php_and_unicode function unicode_to_utf8( $str ) { $utf8 = ''; foreach( $str as $unicode ) { if ( $unicode < 128 ) { $utf8.= chr( $unicode ); } elseif ( $unicode < 2048 ) { $utf8.= chr( 192 + ( ( $unicode - ( $unicode % 64 ) ) / 64 ) ); $utf8.= chr( 128 + ( $unicode % 64 ) ); } else { $utf8.= chr( 224 + ( ( $unicode - ( $unicode % 4096 ) ) / 4096 ) ); $utf8.= chr( 128 + ( ( ( $unicode % 4096 ) - ( $unicode % 64 ) ) / 64 ) ); $utf8.= chr( 128 + ( $unicode % 64 ) ); } // if } // foreach return $utf8; } // unicode_to_utf8 ?>