54 $this->Tags =
get_package(
'string::tags' ,
'last' , __FILE__ );
92 $RawWords = strip_tags( $this->Tags->compile_phpbb_tags( $String ) );
93 $RawWords = str_replace(
"\r" ,
' ' , $RawWords );
94 $RawWords = str_replace(
"\n" ,
' ' , $RawWords );
95 $RawWords = explode(
' ' , $RawWords );
97 foreach( $RawWords as $Key => $Value )
99 if( strlen( $Value ) > $MaxWordLength )
101 $Parts = chunk_split( $Value , $MaxWordLength ,
'[br]' );
102 $String = str_replace( $Value , $Parts , $String );
108 catch( Exception $e )
140 if( $Str !==
false && strlen( $Str ) )
142 if( ord( @$Str[ 0 ] ) === 239 && ord( @$Str[ 1 ] ) === 187 && ord( @$Str[ 2 ] ) === 191 )
144 $Str = substr( $Str , 3 );
150 catch( Exception $e )
182 if( isset( $Strings[ 0 ] ) ===
false )
188 $MaxLength = strlen( $Strings[ 0 ] );
189 for( $i = 0 ; $i < $MaxLength ; $i++ )
191 foreach( $Strings as $j => $String )
193 if( $Strings[ 0 ][ $i ] != $String[ $i ] )
195 return( $CommonPrefix );
198 $CommonPrefix .= $Strings[ 0 ][ $i ];
201 return( $CommonPrefix );
203 catch( Exception $e )
239 if( $CommonPrefix ===
false )
244 if( $CommonPrefix !==
'' )
246 foreach( $Strings as $i => $String )
248 $Strings[ $i ] = str_replace( $CommonPrefix ,
'' , $String );
254 catch( Exception $e )
270 var
$WINPatternL =
'~([\270])|([\340-\347])|([\350-\357])|([\360-\367])|([\370-\377])~s';
282 var
$WINPatternU =
'~([\250])|([\300-\307])|([\310-\317])|([\320-\327])|([\330-\337])~s';
294 var
$KOIPatternL =
'~([\243])|([\300-\307])|([\310-\317])|([\320-\327])|([\330-\337])~s';
306 var
$KOIPatternU =
'~([\263])|([\340-\347])|([\350-\357])|([\360-\367])|([\370-\377])~s';
334 private function init_basic_patterns()
342 $this->Patterns[
'search_l_u' ] =
"~([\xD1\x91])|([\xD1\x80-\x8F])|([\xD0\xB0-\xBF])~s";
343 $this->Patterns[
'search_U_u' ] =
"~([\xD0\x81])|([\xD0\x90-\x9F])|([\xD0\xA0-\xAF])~s";
345 catch( Exception $e )
365 private function init_iso()
369 $this->Patterns[
'search_l_i' ] =
'~([\361])|([\320-\327])|([\330-\337])|([\340-\347])|([\350-\357])~s';
370 $this->Patterns[
'search_U_i' ] =
'~([\241])|([\260-\267])|([\270-\277])|([\300-\307])|([\310-\317])~s';
372 catch( Exception $e )
392 private function init_mac()
396 $this->Patterns[
'search_l_m' ] =
'~([\336])|([\340-\347])|([\350-\357])|'.
397 '([\360-\367])|([\370-\370])|([\337])~s';
398 $this->Patterns[
'search_U_m' ] =
'~([\335])|([\200-\207])|([\210-\217])|([\220-\227])|([\230-\237])~s';
400 catch( Exception $e )
420 private function init_ibm_1()
424 $this->Patterns[
'search_l_c' ] =
'~([\204])|([\234])|([\236])|([\240])|([\242])|([\244])|([\246])|'.
425 '([\250])|([\252])|([\254])|([\265])|([\267])|([\275])|([\306])|'.
426 '([\320])|([\322])|([\324])|([\326])|([\330])|([\340])|([\341])|'.
427 '([\343])|([\345])|([\347])|([\351])|([\353])|([\355])|([\361])|'.
428 '([\363])|([\365])|([\367])|([\371])|([\373])~s';
430 catch( Exception $e )
450 private function init_ibm_2()
454 $this->Patterns[
'search_U_c' ] =
'~([\205])|([\235])|([\237])|([\241])|([\243])|([\245])|([\247])|'.
455 '([\251])|([\253])|([\255])|([\266])|([\270])|([\276])|([\307])|'.
456 '([\321])|([\323])|([\325])|([\327])|([\335])|([\336])|([\342])|'.
457 '([\344])|([\346])|([\350])|([\352])|([\354])|([\356])|([\362])|'.
458 '([\364])|([\366])|([\370])|([\372])|([\374])~s';
460 catch( Exception $e )
480 private function init_ibm_3()
484 $this->Patterns[
'search_l_a' ] =
'~([\361])|([\240-\247])|([\250-\257])|([\340-\347])|([\350-\357])~s';
485 $this->Patterns[
'search_U_a' ] =
'~([\360])|([\200-\207])|([\210-\217])|([\220-\227])|([\230-\237])~s';
487 catch( Exception $e )
507 private function init_patterns()
511 $this->init_basic_patterns();
518 catch( Exception $e )
546 private function get_enc_regexp( $Name )
550 if( isset( $this->Patterns[ $Name ] ) )
552 return( $this->Patterns[ $Name ] );
555 throw(
new Exception(
'Illegal pattern name' ) );
557 catch( Exception $e )
585 private function analize_detection_results( $Charsets )
590 $key = key( $Charsets );
592 if( max( $Charsets ) == 0 )
599 case(
'w' ):
return(
'cp1251' );
600 case(
'k' ):
return(
'koi8-r' );
601 case(
'i' ):
return(
'iso-8859-5' );
602 case(
'm' ):
return(
'x-mac-cyrillic' );
603 case(
'a' ):
return(
'ibm866' );
604 case(
'c' ):
return(
'ibm855' );
605 case(
'u' ):
return(
'utf-8' );
610 catch( Exception $e )
642 private function try_encoding( &$Charsets , $Content , $TryCharset )
646 $Result = preg_match_all(
647 $this->get_enc_regexp(
"search_l_$TryCharset" ) , $Content , $Arr , PREG_PATTERN_ORDER
652 $Charsets[ $TryCharset ] += count( $Arr[ 0 ] ) * 3;
655 $Result = preg_match_all(
656 $this->get_enc_regexp(
"search_U_$TryCharset" ) , $Content , $Arr , PREG_PATTERN_ORDER
661 $Charsets[ $TryCharset ] += count( $Arr[ 0 ] );
664 catch( Exception $e )
696 $Charsets = array (
'w' => 0,
'k' => 0,
'i' => 0,
'm' => 0,
'a' => 0,
'c' => 0,
'u' => 0 );
698 $this->try_encoding( $Charsets , $Content ,
'w' );
700 $this->try_encoding( $Charsets , $Content ,
'k' );
702 $this->try_encoding( $Charsets , $Content ,
'i' );
704 $this->try_encoding( $Charsets , $Content ,
'm' );
706 $this->try_encoding( $Charsets , $Content ,
'a' );
708 $this->try_encoding( $Charsets , $Content ,
'c' );
710 $this->try_encoding( $Charsets , $Content ,
'u' );
712 return( $this->analize_detection_results( $Charsets ) );
714 catch( Exception $e )
754 function iconv( $InCharset , $OutCharset , $Data )
758 if( is_array( $Data ) || is_object( $Data ) )
760 foreach( $Data as $Key => $Value )
762 set_field( $Data , $Key , $this->
iconv( $InCharset , $OutCharset , $Value ) );
768 if( $InCharset ===
false )
772 return( @
iconv( $InCharset , $OutCharset , $Data ) );
775 catch( Exception $e )