function test_substr()
 {
     printf("Test string: %s <br>", self::$test_str);
     printf("Habari encoding: %s <br>", MultiByte::hab_encoding());
     printf("mb_internal_encoding: %s <br>", mb_internal_encoding());
     printf("MultiByte detected encoding of test string: %s <br>", MultiByte::detect_encoding(self::$test_str));
     printf("mbstring detected encoding of test string: %s <br>", mb_detect_encoding(self::$test_str));
     $this->assert_equal(MultiByte::substr(self::$test_str, 1, 3), mb_substr(self::$test_str, 1, 3));
     $this->assert_equal(MultiByte::substr(self::$test_str, 1, 3), mb_substr(self::$test_str, 1, 3, mb_detect_encoding(self::$test_str)));
     $this->assert_equal(MultiByte::substr(self::$test_str, 5), mb_substr(self::$test_str, 5));
     printf(" MultiByte substring (begin-1 end-3): %s <br>", MultiByte::substr(self::$test_str, 1, 3));
     printf(" MultiByte substring 2 (begin-5 end-null): %s <br>", MultiByte::substr(self::$test_str, 5));
     printf(" mbstring substring without encoding detected (begin-1 end-3): %s <br>", mb_substr(self::$test_str, 1, 3));
     printf(" mbstring substring with encoding detected (begin-1 end-3): %s <br>", mb_substr(self::$test_str, 1, 3, mb_detect_encoding(self::$test_str)));
     printf(" mbstring substring 2 without encoding detected(begin-5 end-null): %s <br>", mb_substr(self::$test_str, 5));
 }
Exemple #2
0
 public function test_detect_encoding()
 {
     $this->assert_equal(MultiByte::detect_encoding('foo'), 'ASCII');
     $str = MultiByte::convert_encoding($this->test_strings['jis'], 'JIS');
     $this->assert_equal(MultiByte::detect_encoding($str), 'JIS');
 }
Exemple #3
0
 public static function convert_encoding($str, $use_enc = null, $from_enc = null)
 {
     $ret = false;
     $enc = self::$hab_enc;
     if ($use_enc !== null) {
         $enc = $use_enc;
     }
     if (self::$use_library == self::USE_MBSTRING) {
         if ($from_enc == null) {
             $from_enc = MultiByte::detect_encoding($str);
         }
         $ret = mb_convert_encoding($str, $enc, $from_enc);
     }
     return $ret;
 }
 public function test_detect_encoding()
 {
     $this->assert_false(MultiByte::detect_encoding('foo'));
 }
Exemple #5
0
	public function testDetect_encoding()
	{
		$this->assertEquals( MultiByte::detect_encoding( self::$test_str ), mb_detect_encoding( self::$test_str ) );
	}
Exemple #6
0
 public static function convert_encoding($str, $use_enc = null, $from_enc = null)
 {
     $ret = FALSE;
     $enc = self::$hab_enc;
     if ($use_enc !== null) {
         $enc = $use_enc;
     }
     if (self::$use_library == self::USE_MBSTRING) {
         if (extension_loaded('mbstring')) {
             if ($from_enc == null) {
                 $from_enc = MultiByte::detect_encoding($str);
             }
             $ret = mb_convert_encoding($str, $enc, $from_enc);
         }
     }
     return $ret;
 }
Exemple #7
0
		public function test_detect_encoding ( ) {
			
			$this->assert_equal( MultiByte::detect_encoding( 'foo' ), 'ASCII' );
			$this->assert_equal( MultiByte::detect_encoding( $this->test_strings['jis'] ), 'JIS' );
			//echo MultiByte::detect_encoding( '' ); die();
			
		}