| 
webmaster@0
 | 
     1 <?php | 
| 
webmaster@0
 | 
     2     class TextUtils | 
| 
webmaster@0
 | 
     3     { | 
| 
webmaster@0
 | 
     4 	public static function SplitTags($str) | 
| 
webmaster@0
 | 
     5 	{ | 
| 
webmaster@0
 | 
     6 	    $str = str_replace("\\\"", "\"", $str); | 
| 
webmaster@0
 | 
     7 	    $tags = array(); | 
| 
webmaster@0
 | 
     8 	    preg_match_all('/"([a-zA-Z0-9 ]+)"/', $str, $tests); | 
| 
webmaster@0
 | 
     9 	    $useful = $tests[1]; | 
| 
webmaster@0
 | 
    10 	    foreach($useful as $match) | 
| 
webmaster@0
 | 
    11 	    { | 
| 
webmaster@0
 | 
    12 		$tags[] = $match; | 
| 
webmaster@0
 | 
    13 		$str = str_replace("\"{$match}\"", null, $str); | 
| 
webmaster@0
 | 
    14 	    } | 
| 
webmaster@0
 | 
    15 	    $str = preg_replace("/( )+/", " ", trim($str)); | 
| 
webmaster@0
 | 
    16 	    if(strlen($str) > 0) | 
| 
webmaster@0
 | 
    17 		$tags = array_merge($tags, explode(" ", $str)); | 
| 
webmaster@0
 | 
    18 	    asort($tags); | 
| 
webmaster@0
 | 
    19 	    return $tags; | 
| 
webmaster@0
 | 
    20 	} | 
| 
webmaster@0
 | 
    21 	 | 
| 
webmaster@0
 | 
    22 	public static function DiffTagLine($old, $new, &$ajout, &$suppr) | 
| 
webmaster@0
 | 
    23 	{ | 
| 
webmaster@0
 | 
    24 	    $arOld = TextUtils::SplitTags($old); | 
| 
webmaster@0
 | 
    25 	    $arNew = TextUtils::SplitTags($new); | 
| 
webmaster@0
 | 
    26 	    $ajout = array_diff($arNew, $arOld); | 
| 
webmaster@0
 | 
    27 	    $suppr = array_diff($arOld, $arNew); | 
| 
webmaster@0
 | 
    28 	} | 
| 
webmaster@10
 | 
    29  | 
| 
webmaster@10
 | 
    30     public static function StripTitle($Titre) { | 
| 
webmaster@10
 | 
    31         $Titre_url = str_replace(" ", "_", strip_tags($Titre)); | 
| 
webmaster@10
 | 
    32 		$Titre_url = str_replace("-", "_", $Titre_url); | 
| 
webmaster@10
 | 
    33         $Titre_url = str_replace(array("é", "è"), "e", $Titre_url); | 
| 
webmaster@10
 | 
    34         $Titre_url = str_replace("à", "a", $Titre_url); | 
| 
webmaster@10
 | 
    35         $Titre_url = str_replace("ù", "u", $Titre_url); | 
| 
webmaster@10
 | 
    36         $Titre_url = str_replace(array("î", "ï"), "i", $Titre_url); | 
| 
webmaster@10
 | 
    37         return $Titre_url; | 
| 
webmaster@0
 | 
    38     } | 
| 
webmaster@10
 | 
    39  | 
| 
webmaster@10
 | 
    40     public static function getMonthName($monthNumber) { | 
| 
webmaster@10
 | 
    41         return ucfirst(strftime('%B', strtotime('2007-' . $monthNumber . '-01'))); | 
| 
webmaster@10
 | 
    42     } | 
| 
webmaster@53
 | 
    43  | 
| 
webmaster@53
 | 
    44     public static function EnsureUTF8($string) { | 
| 
webmaster@53
 | 
    45         return TextUtils::SeemsUTF8($string) ? $string : utf8_encode($string); | 
| 
webmaster@53
 | 
    46     } | 
| 
webmaster@53
 | 
    47  | 
| 
webmaster@53
 | 
    48     public static function SeemsUTF8($Str) { | 
| 
webmaster@53
 | 
    49         for ($i=0; $i<strlen($Str)/10 || $i < 100; $i++) { | 
| 
webmaster@53
 | 
    50             if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb | 
| 
webmaster@53
 | 
    51             elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb | 
| 
webmaster@53
 | 
    52             elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb | 
| 
webmaster@53
 | 
    53             elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb | 
| 
webmaster@53
 | 
    54             elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb | 
| 
webmaster@53
 | 
    55             elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b | 
| 
webmaster@53
 | 
    56             else return false; # Does not match any model | 
| 
webmaster@53
 | 
    57             for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? | 
| 
webmaster@53
 | 
    58                 if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) | 
| 
webmaster@53
 | 
    59                     return false; | 
| 
webmaster@53
 | 
    60 	        } | 
| 
webmaster@53
 | 
    61         } | 
| 
webmaster@53
 | 
    62         return true; | 
| 
webmaster@53
 | 
    63     } | 
| 
webmaster@10
 | 
    64     } | 
| 
webmaster@10
 | 
    65 ?> |