/** * Retourne une liste de lettres correspondant aux 1ères lettres des mots d'un texte. * * @param string $texte * @return string|array */ function premieres_lettres($texte) { //print_r($texte); $a = "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ"; $texte = strtr($texte, "\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF", "!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy"); $texte = strtr($texte, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH", "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th")); //array des mots interdits à compléter $mots_interdits = array(':','quot','sous','avec','sans','pour','etc','dans','general','autoconstruire','autoconstruction','autoconstruites','autoconstruits','autoconstruite','Autoconstruction'); // liste des mots if ($mots = str_word_count($texte, 1, $a)) { // on stocke la 1ère lettre de chaque mot dans un tableau $lettres = array(); foreach($mots as $mot) { // on ne prend en compte que les mots d'au moins 4 octets if (strlen($mot) > 3 AND !in_array($mot,$mots_interdits)){ $lettres = array_merge($lettres, array(strtoupper(substr($mot,0,1)))); //print_r($lettres); } } if (count($lettres)) { $texte = $lettres; //print_r($texte); } } return $texte; }