Advertisement
Guest User

Untitled

a guest
Dec 24th, 2010
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1.         // Solution 1
  2.         $inistring = "Peut être à 100€ ou à 100$ ou 68£, ça ne fonctionne \n pas ^^";
  3.         $string = preg_replace(array('@\pM@u', '/^(.)/ue', '/\s+(.)/ue'), array('', 'lcfirst(\'\\1\')', 'ucfirst(\'\\1\')'), \normalizer::normalize(trim($inistring), Normalizer::FORM_D));
  4.         var_dump($string);
  5.         // Solution 2
  6.         $string = lcfirst(preg_replace('/[\s\'^`,]+/u', '', ucwords(strtolower(iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', trim($inistring))))));
  7.         var_dump($string);
  8.         // Solution 3
  9.         $s = preg_replace('/\s+/u', ' ', $inistring);
  10.         $s = trim($s);
  11.  
  12.         if ('' !== $s)
  13.         {
  14.           // UTF-8 to ASCII transliteration
  15.           if (preg_match("'[\x80-\xFF]'", $s))
  16.           {
  17.             $s = Normalizer::normalize($s, Normalizer::FORM_KD);
  18.             $s = preg_replace('/\p{Mn}+/u', '', $s);
  19.             $s = iconv('UTF-8', 'ASCII' . ('glibc' !== ICONV_IMPL ? '//IGNORE' : '') . '//TRANSLIT', $s);
  20.           }
  21.  
  22.           // Camel-case
  23.           $s = strtolower($s);
  24.           $s = ucwords($s);
  25.           $s[0] = strtolower($s[0]);
  26.  
  27.           // Remove spaces
  28.           $s = str_replace(' ', '', $s);
  29.         }
  30.         var_dump($s);
  31.  
  32. // Résultats :
  33. // string(48) "peutEtreA100€OuA100$Ou68£,CaNeFonctionnePas^^"
  34. // string(45) "peutetrea100eurOua100$Ou68lbCaNeFonctionnePas"
  35. // string(48) "peutEtreA100eurOuA100$Ou68lb,CaNeFonctionnePas^^"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement