Example #1
0
 /**
  * Combine function trimText and cleanTruncate for input
  * @param string $str
  * @param intégrer $lg_max
  * @param string $delimiter
  * @return string
  */
 public static function truncateClean($str, $lg_max, $delimiter)
 {
     return filter_escapeHtml::trim(filter_string::truncate($str, $lg_max, $delimiter));
 }
Example #2
0
 /**
 * Converti une chaine en URL valide
 * @static
 * @param string $str
 * @param array $option
 * @return mixed|string
 * @throws Exception
 * @example:
     http_url::clean(
    '/public/test/truc-machin01/aussi/version-1.0/',
    array('dot'=>'display','ampersand'=>'strict','cspec'=>array('[\/]'),'rspec'=>array(''))
    );
 */
 public static function clean($str, $option = array('dot' => false, 'ampersand' => 'none', 'cspec' => '', 'rspec' => ''))
 {
     /**Clean accent*/
     $Caracs = array("¥" => "Y", "µ" => "u", "À" => "A", "Á" => "A", "Â" => "A", "Ã" => "A", "Ä" => "A", "Å" => "A", "Æ" => "A", "Ç" => "C", "È" => "E", "É" => "E", "Ê" => "E", "Ë" => "E", "Ì" => "I", "Í" => "I", "Î" => "I", "Ï" => "I", "Ð" => "D", "Ñ" => "N", "Ò" => "O", "Ó" => "O", "Ô" => "O", "Õ" => "O", "Ö" => "O", "Ø" => "O", "Ù" => "U", "Ú" => "U", "Û" => "U", "Ü" => "U", "Ý" => "Y", "ß" => "s", "à" => "a", "á" => "a", "â" => "a", "ã" => "a", "ä" => "a", "å" => "a", "æ" => "a", "ç" => "c", "è" => "e", "é" => "e", "ê" => "e", "ë" => "e", "ì" => "i", "í" => "i", "î" => "i", "ï" => "i", "ð" => "o", "ñ" => "n", "ò" => "o", "ó" => "o", "ô" => "o", "õ" => "o", "ö" => "o", "ø" => "o", "ù" => "u", "ú" => "u", "û" => "u", "ü" => "u", "ý" => "y", "ÿ" => "y");
     $str = strtr("{$str}", $Caracs);
     $str = trim($str);
     if (is_bool($option)) {
         if ($option != false) {
             /*replace & => $amp (w3c convert)*/
             $str = str_replace('&', '&', $str);
             $str = str_replace('.', '', $str);
         }
     } elseif (is_array($option)) {
         if (array_key_exists('dot', $option)) {
             if ($option['dot'] == 'none') {
                 $str = str_replace('.', '', $str);
             }
         }
         if (array_key_exists('ampersand', $option)) {
             if ($option['ampersand'] == 'strict') {
                 /*replace & => $amp (w3c convert)*/
                 $str = str_replace('&', '&', $str);
             } elseif ($option['ampersand'] == 'none') {
                 /*replace & => ''*/
                 $str = str_replace('&', '', $str);
             } else {
                 /*replace & => $amp (w3c convert)*/
                 $str = str_replace('&', '&', $str);
             }
         }
     }
     /* stripcslashes backslash */
     $str = filter_escapeHtml::cleanQuote($str);
     $tbl_o = array("@'@i", '@[[:blank:]]@i', '[\\?]', '[\\#]', '[\\@]', '[\\,]', '[\\!]', '[\\:]', '[\\(]', '[\\)]');
     $tbl_r = array('-', '-', "", "", "", "", "", "", "", "");
     $cSpec = '';
     $rSpec = '';
     if (is_array($option)) {
         if (array_key_exists('cspec', $option) and array_key_exists('rspec', $option)) {
             if (is_array($option['cspec']) and is_array($option['rspec'])) {
                 if ($option['cspec'] != '' and $option['rspec'] != '') {
                     $cSpec = array_merge($tbl_o, $option['cspec']);
                     $rSpec = array_merge($tbl_r, $option['rspec']);
                 } else {
                     throw new Exception('cspec or rspec option is NULL');
                 }
             } else {
                 /*replace blank and special caractère*/
                 $cSpec = $tbl_o;
                 $rSpec = $tbl_r;
             }
         } else {
             /*replace blank and special caractère*/
             $cSpec = $tbl_o;
             $rSpec = $tbl_r;
         }
     } else {
         /*replace blank and special caractère*/
         $cSpec = $tbl_o;
         $rSpec = $tbl_r;
     }
     /*Removes the indent if end of string*/
     $str = rtrim(preg_replace($cSpec, $rSpec, $str), "-");
     /*Convert UTF8 encode*/
     $str = filter_htmlentities::decode_utf8($str);
     /*Convert lower case*/
     $str = filter_string::strtolower($str);
     return $str;
 }