view includes/class.textutils.php @ 59:caef2b6e5690

Necessaire pour IE ! Le tag est sinon vide et se retrouve compacté J'avais modifie ca pour rendre le validateur HTML5 content, mais, ce n'est pas vraiment une bonne idee, car sinon le parser XML voit un tag vide, et par consequent lorsqu'il prepare la sortie, il produit un <script /> qu'IE est incapable de gerer correctement.
author Franck Deroche <webmaster@defr.org>
date Tue, 19 Feb 2008 02:54:58 -0800
parents ec0c926a78a6
children
line wrap: on
line source
<?php
    class TextUtils
    {
	public static function SplitTags($str)
	{
	    $str = str_replace("\\\"", "\"", $str);
	    $tags = array();
	    preg_match_all('/"([a-zA-Z0-9 ]+)"/', $str, $tests);
	    $useful = $tests[1];
	    foreach($useful as $match)
	    {
		$tags[] = $match;
		$str = str_replace("\"{$match}\"", null, $str);
	    }
	    $str = preg_replace("/( )+/", " ", trim($str));
	    if(strlen($str) > 0)
		$tags = array_merge($tags, explode(" ", $str));
	    asort($tags);
	    return $tags;
	}
	
	public static function DiffTagLine($old, $new, &$ajout, &$suppr)
	{
	    $arOld = TextUtils::SplitTags($old);
	    $arNew = TextUtils::SplitTags($new);
	    $ajout = array_diff($arNew, $arOld);
	    $suppr = array_diff($arOld, $arNew);
	}

    public static function StripTitle($Titre) {
        $Titre_url = str_replace(" ", "_", strip_tags($Titre));
		$Titre_url = str_replace("-", "_", $Titre_url);
        $Titre_url = str_replace(array("é", "è"), "e", $Titre_url);
        $Titre_url = str_replace("à", "a", $Titre_url);
        $Titre_url = str_replace("ù", "u", $Titre_url);
        $Titre_url = str_replace(array("î", "ï"), "i", $Titre_url);
        return $Titre_url;
    }

    public static function getMonthName($monthNumber) {
        return ucfirst(strftime('%B', strtotime('2007-' . $monthNumber . '-01')));
    }

    public static function EnsureUTF8($string) {
        return TextUtils::SeemsUTF8($string) ? $string : utf8_encode($string);
    }

    public static function SeemsUTF8($Str) {
        for ($i=0; $i<strlen($Str)/10 || $i < 100; $i++) {
            if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
            elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
            elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
            elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
            elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
            elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
            else return false; # Does not match any model
            for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
                if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
                    return false;
	        }
        }
        return true;
    }
    }
?>