Initialise la donnée
* * @param chaine source de données */ function __construct($src) { $this->src=$src; } /** *String to html * *Transforme une chaine de caractère au format HTML à partir de $src
* */ function strToHtml() { $tmp=htmlspecialchars($this->src, ENT_QUOTES); $tmp=str_replace(chr(13).chr(10),"Transforme du code HTML en chaine de caractère à partir de $src
* */ function htmlToStr() { $tmp=$this->src; $tmp=unhtmlentities($tmp); $tmp=str_replace("Récupere le debut d'une chaine de caractere (nbChar)
* * @param entier nombre de caractère à récuperer */ function strCut($nbChar) { $tmp=$this->src; # On enleve les retours à la ligne $tmp=str_replace(chr(13).chr(10),"",$tmp); $strlen=strlen($tmp); # Si la taille n'est pas valide if ($strlen>$nbChar) { $tmp=substr($tmp,0,$nbChar); } return $tmp; } /** *HtmlCut * *Récupere le debut du texte d'une chaine html (nbChar)
* * @param entier nombre de caractère à récuperer */ function htmlCut($nbChar) { $tmp=$this->src; # On enlève les espaces superflux while (!(strpos($tmp, " ")===false)) { $tmp=str_replace(" "," ",$tmp); } # on enlève les caractères spéciaux $tmp=unhtmlentities($tmp); // $tmp = mb_eregi_replace("^[[:space:]]*[a-z]+[.)".chr(176)."]([[:space:]]*)", "",$tmp); # on a maintenant une chaine propre à l'utilisation... # On enleve les retours à la ligne $tmp=str_replace(chr(13).chr(10),"",$tmp); $strlen=strlen($tmp); # Si la taille n'est pas valide if ($strlen>$nbChar) { $tmp=substr($tmp,0,$nbChar)." ..."; } //$tmp = addslashes(stripslashes($tmp)); return $tmp; } function truncateHtml($length = 500, $ending = '...', $exact = false, $considerHtml = true) { $text=$this->src; if ($considerHtml) { // if the plain text is shorter than the maximum length, return the whole text if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { return $text; } // splits all html-tags to scanable lines preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); $total_length = strlen($ending); $open_tags = array(); $truncate = ''; foreach ($lines as $line_matchings) { // if there is any html-tag in this line, handle it and add it (uncounted) to the output if (!empty($line_matchings[1])) { // if it's an "empty element" with or without xhtml-conform closing slash if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { // do nothing // if tag is a closing tag } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { // delete tag from $open_tags list $pos = array_search($tag_matchings[1], $open_tags); if ($pos !== false) { unset($open_tags[$pos]); } // if tag is an opening tag } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { // add tag to the beginning of $open_tags list array_unshift($open_tags, strtolower($tag_matchings[1])); } // add html-tag to $truncate'd text $truncate .= $line_matchings[1]; } // calculate the length of the plain text part of the line; handle entities as one character $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); if ($total_length+$content_length> $length) { // the number of characters which are left $left = $length - $total_length; $entities_length = 0; // search for html entities if (preg_match_all('/&[0-9a-z]{2,8};|[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { // calculate the real length of all entities in the legal range foreach ($entities[0] as $entity) { if ($entity[1]+1-$entities_length <= $left) { $left--; $entities_length += strlen($entity[0]); } else { // no more characters left break; } } } $truncate .= substr($line_matchings[2], 0, $left+$entities_length); // maximum lenght is reached, so get off the loop break; } else { $truncate .= $line_matchings[2]; $total_length += $content_length; } // if the maximum length is reached, get off the loop if($total_length>= $length) { break; } } } else { if (strlen($text) <= $length) { return $text; } else { $truncate = substr($text, 0, $length - strlen($ending)); } } // if the words shouldn't be cut in the middle... if (!$exact) { // ...search the last occurance of a space... $spacepos = strrpos($truncate, ' '); if (isset($spacepos)) { // ...and cut the text in this position $truncate = substr($truncate, 0, $spacepos); } } // add the defined ending to the text $truncate .= $ending; if($considerHtml) { // close all unclosed html-tags foreach ($open_tags as $tag) { $truncate .= '' . $tag . '>'; } } return $truncate; } function chainCut($nbChar) { $tmp=$this->src; // # On enlève les espaces superflux // while (!(strpos($tmp, " ")===false)) // { // $tmp=str_replace(" "," ",$tmp); // } # on enlève les caractères spéciaux $tmp=unhtmlentities($tmp); // $tmp = mb_eregi_replace("^[[:space:]]*[a-z]+[.)".chr(176)."]([[:space:]]*)", "",$tmp); # on a maintenant une chaine propre à l'utilisation... # On enleve les retours à la ligne $tmp=str_replace(chr(13).chr(10),"",$tmp); $strlen=strlen($tmp); # Si la taille n'est pas valide if ($strlen>$nbChar) { $tmp=substr($tmp,0,$nbChar)." ..."; } //$tmp = addslashes(stripslashes($tmp)); return $tmp; } /** *Str To Sql * *Transforme une chaine de caractères en chaine Sql à partir de $src
* *Utilisation de htmlentities
* */ function strToSql() { $tmp=$this->src; $tmp=htmlentitiesconv($tmp); //stockés en htmlentities return $tmp; } /** *Html To Sql * *Transforme une chaine de caractères au format HTML à partir de $src
* */ function htmlToSql() { $tmp=$this->src; return $tmp; } /** *SQL To Str * *Transforme une chaine de caractères à partir de $src
* */ function sqlToStr() { $tmp=$this->src; return $tmp; } /** *SQL To Html * *Transforme une chaine de caractères au format HTML à partir de $src
* */ function sqlToHtml() { $tmp=$this->src; return $tmp; } /** * bytexor * @private */ function bytexor($a,$b,$l) { $c=""; for($i=0;$i<$l;$i++) { $c.=$a[$i]^$b[$i]; } return($c); } /** * binmd5 * @private */ function binmd5($val) { return(pack("H*",md5($val))); } /* *Decrypt *Decryptage de la source de donnée à partir d'une clé
* * @param chaine * @desc clé de l'encryptage * @return chaine * @desc chaine décryptée à partir de la source de l'objet (source cryptée) */ function decrypt($paramKey) { $msg=$this->src; $key=$paramKey;$sifra=""; $key1=$this->binmd5($key); while($msg) { $m=substr($msg,0,16); $msg=substr($msg,16); $sifra.=$m=$this->bytexor($m, $key1, strlen($m)); $key1=$this->binmd5($key.$key1.$m); } return($sifra); } /* *Encryptage *Encryptage de la source de donnée à partir d'une clé
* * @param chaine * @desc clé de l'encryptage * @return chaine * @desc chaine cryptée à partir de la source de l'objet' */ function encrypt($paramKey) { $msg=$this->src; $key=$paramKey;$sifra=""; $key1=$this->binmd5($key); while($msg) { $m=substr($msg,0,16); $msg=substr($msg,16); $sifra.=$this->bytexor($m, $key1, strlen($m)); $key1=$this->binmd5($key.$key1.$m); } return($sifra); } /* * formatNameClean *Enléve tous les characteres spéciaux
* * @return chaine * @desc chaine chaine sans caractéres spéciaux */ function formatNameClean() { $ch = $this->src; /*Fonction permettant de supprimer les numeros, le point et l'espace à l'affichage*/ $ch = eregi_replace("^[[:space:]]*[a-z]+[.)".chr(176)."][[:space:]]+", "", $ch); $s = strtolower($ch); # Gestion des char remplacables $s=ereg_replace("à|À|â|Â|ä|Ä","a",$s); $s=ereg_replace("ç|Ç","c",$s); $s=ereg_replace("è|È|é|É|ê|Ê|ë|Ë","e",$s); $s=ereg_replace("î|Î|ï|Ï","i",$s); $s=ereg_replace("ô|Ô","o",$s); $s=ereg_replace("ù|Ù|û|Û","u",$s); # Gestion des espaces $s=ereg_replace(" | |-|/|,","_",$s); $nb=strlen($s); $i=0; while($i<$nb) { // Suppression de tous les chars spèciaux!!! if ( ((ord(substr($s,$i,1))<97) || (ord(substr($s,$i,1))>122)) && ((ord(substr($s,$i,1))!=95)) ){ $s=substr($s,0,$i).substr($s,($i+1)); $i=0; $nb=strlen($s); } $i++; } if (strlen($s)>25) $s=substr($s,0,25); return $s; } /* * formatNameClean *Enléve tous les characteres spéciaux
* * @return chaine * @desc chaine chaine sans caractéres spéciaux */ function formatNameWidthNumberClean() { $ch = $this->src; /*Fonction permettant de supprimer les numeros, le point et l'espace à l'affichage*/ $ch = eregi_replace("^[[:space:]]*[a-z][0-9]+[.)".chr(176)."][[:space:]]+", "", $ch); $s = strtolower($ch); # Gestion des char remplacables $s=ereg_replace("à|À|â|Â|ä|Ä","a",$s); $s=ereg_replace("ç|Ç","c",$s); $s=ereg_replace("è|È|é|É|ê|Ê|ë|Ë","e",$s); $s=ereg_replace("î|Î|ï|Ï","i",$s); $s=ereg_replace("ô|Ô","o",$s); $s=ereg_replace("ù|Ù|û|Û","u",$s); # Gestion des espaces $s=ereg_replace(" | |-|/|,","_",$s); $nb=strlen($s); $i=0; while($i<$nb) { // Suppression de tous les chars spèciaux!!! if ( ((ord(substr($s,$i,1))<48) || (ord(substr($s,$i,1))>57)) && ((ord(substr($s,$i,1))<97) || (ord(substr($s,$i,1))>122)) && ((ord(substr($s,$i,1))!=95)) ){ $s=substr($s,0,$i).substr($s,($i+1)); $i=0; $nb=strlen($s); } $i++; } if (strlen($s)>25) $s=substr($s,0,25); return $s; } /* * NoSpecialChar *Enléve tous les characteres spéciaux
* * @return chaine * @desc chaine chaine sans caractéres spéciaux */ function noSpecialChar() { $tmp=$this->src; $tmp=strtoupper($tmp); $i=1; $retourValue=""; while ($i <= strlen($tmp)) { $testValue=substr($tmp,$i-1,1); if (($testValue>="A" && $testValue<="Z") || ($testValue>="0" && $testValue<="9")) { $retourValue.=$testValue; } $i++; } return $retourValue; } /* * StripHtmlTags *Enléve toutes les tags HTML
* * @return chaine * @desc chaine chaine sans caractéres spéciaux */ function stripHtmlTags() { $tmp=strip_tags($this->src); $tmp=unhtmlentities($tmp); return $tmp; } } ?>