Page 1 sur 1

changer les caractères textes par des image

Posté : 04 sept. 2009, 17:42
par stefane321
Bonjour,

j'essaie de faire une fonction qui va changer les caractères texte d'une chaine par des belle lettre en image faite dans photoshop

jai créer mes images et jai fait un bout de code qui change mes caractères.... mais sa marche pas

pouvez-vous m'aider svp?

Merci!

Code : Tout sélectionner

<?php $mot="CALCULE LA TAILLE D'UNE CHAÎNE"; echo strlen($mot); $nb= strlen($mot); $arr1 = str_split($mot); for($i=0;$i < $nb;$i++) { $car_speciaux = array( 'A','B','C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'É', 'È','Ê', 'Ë', 'Ô', 'Ö', 'Ò', 'Û', 'Ù', 'À', 'Â', 'Î', 'Ï', 'Ç'); $car_normaux = array( 'M-LG_01.png','M-LG_02.png','M-LG_03.png', 'M-LG_04.png', 'M-LG_05.png', 'M-LG_06.png', 'M-LG_07.png', 'M-LG_08.png', 'M-LG_09.png', 'M-LG_10.png', 'M-LG_11.png', 'M-LG_12.png', 'M-LG_13.png', 'M-LG_14.png', 'M-LG_15.png', 'M-LG_16.png', 'M-LG_17.png', 'M-LG_18.png', 'M-LG_19.png', 'M-LG_20.png', 'M-LG_21.png', 'M-LG_22.png', 'M-LG_23.png', 'M-LG_24.png', 'M-LG_25.png', 'M-LG_26.png', 'M-LG_27.png', 'M-LG_28.png', 'M-LG_29.png', 'M-LG_30.png', 'M-LG_31.png', 'M-LG_32.png', 'M-LG_33.png', 'M-LG_34.png', 'M-LG_35.png', 'M-LG_36.png', 'M-LG_37.png', 'M-LG_38.png', 'M-LG_38.png', 'M-LG_40.png'); $arr1[$i] = str_replace($car_speciaux, $car_normaux, utf8_encode($arr1[$i])); echo "<IMG SRC=\"images/img-titre/".$arr1[$i]."\" BORDER=\"0\">"; } ?>
Les images:
http://www.motoactionvilleneuve.com/img-titre.zip

Re: changer les caractères textes par des image

Posté : 04 sept. 2009, 17:50
par thehawk
Essaye avec un code de ce genre :
<?php

$mot="CALCULE LA TAILLE D'UNE CHAÎNE";

echo strlen($mot);
$nb= strlen($mot);
$arr1 = str_split($mot);

for($i=0;$i < $nb;$i++)
     {
      $car_speciaux = array( 'A','B','C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'É', 'È','Ê', 'Ë', 'Ô', 'Ö', 'Ò', 'Û', 'Ù', 'À', 'Â', 'Î', 'Ï', 'Ç');
      $car_normaux  = array( 'M-LG_01.png','M-LG_02.png','M-LG_03.png', 'M-LG_04.png', 'M-LG_05.png', 'M-LG_06.png', 'M-LG_07.png', 'M-LG_08.png', 'M-LG_09.png', 'M-LG_10.png', 'M-LG_11.png', 'M-LG_12.png', 'M-LG_13.png', 'M-LG_14.png', 'M-LG_15.png', 'M-LG_16.png', 'M-LG_17.png', 'M-LG_18.png', 'M-LG_19.png', 'M-LG_20.png', 'M-LG_21.png', 'M-LG_22.png', 'M-LG_23.png', 'M-LG_24.png', 'M-LG_25.png', 'M-LG_26.png', 'M-LG_27.png', 'M-LG_28.png', 'M-LG_29.png', 'M-LG_30.png', 'M-LG_31.png', 'M-LG_32.png', 'M-LG_33.png', 'M-LG_34.png', 'M-LG_35.png', 'M-LG_36.png', 'M-LG_37.png', 'M-LG_38.png', 'M-LG_38.png', 'M-LG_40.png');
      $arr1[$i] = str_replace($car_speciaux, '<IMG SRC="images/img-titre/"'.$car_normaux.'" BORDER=\"0\">', utf8_encode($arr1[$i]));
         
       echo $arr1[$i];
     }

?>
Bye hawk

Re: changer les caractères textes par des image

Posté : 04 sept. 2009, 18:01
par thehawk
Une erreur de ma part voici le script normalement fonctionnel :
<?php

$mot="CALCULE LA TAILLE D'UNE CHAÎNE";

echo strlen($mot);
$nb= strlen($mot);
$arr1 = str_split($mot);

$car_speciaux = array( 'A','B','C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'É', 'È','Ê', 'Ë', 'Ô', 'Ö', 'Ò', 'Û', 'Ù', 'À', 'Â', 'Î', 'Ï', 'Ç');
$car_normaux  = array( 'M-LG_01.png','M-LG_02.png','M-LG_03.png', 'M-LG_04.png', 'M-LG_05.png', 'M-LG_06.png', 'M-LG_07.png', 'M-LG_08.png', 'M-LG_09.png', 'M-LG_10.png', 'M-LG_11.png', 'M-LG_12.png', 'M-LG_13.png', 'M-LG_14.png', 'M-LG_15.png', 'M-LG_16.png', 'M-LG_17.png', 'M-LG_18.png', 'M-LG_19.png', 'M-LG_20.png', 'M-LG_21.png', 'M-LG_22.png', 'M-LG_23.png', 'M-LG_24.png', 'M-LG_25.png', 'M-LG_26.png', 'M-LG_27.png', 'M-LG_28.png', 'M-LG_29.png', 'M-LG_30.png', 'M-LG_31.png', 'M-LG_32.png', 'M-LG_33.png', 'M-LG_34.png', 'M-LG_35.png', 'M-LG_36.png', 'M-LG_37.png', 'M-LG_38.png', 'M-LG_38.png', 'M-LG_40.png');
$array  = array_combine($car_speciaux , $car_normaux);	  // Tout d'abord on associe les deux tableaux $array['A'] =  'M-LG_01.png'
	 
for($i=0;$i < $nb;$i++)
     {
		if (array_key_exists($arr1[$i] , $array)) // Si le caractère existe
		{
			echo '<IMG SRC="images/img-titre/"'.$array[$arr1[$i]].'" BORDER="0">'; // On prend l'association de array
		}
		else
		{
			echo $arr1[$i]; // on l'affiche (par exemple les espaces et les '
		}
     }

?>
Bye hawk

Re: changer les caractères textes par des image

Posté : 04 sept. 2009, 18:12
par stefane321
Merci, sa marche

a part un guillemet de trop dans ce bout;

Code : Tout sélectionner

echo '<IMG SRC="images/img-titre/"'.$array[$arr1[$i]].'" BORDER="0">';

Re: changer les caractères textes par des image

Posté : 06 sept. 2009, 11:49
par Ryle
Modération :
Si ta question est résolue, pense à l'indiquer pour que les futures personnes qui voudront consulter ce sujet sachent qu'il contient une solution.
Tu peux réaliser cette opération toi-même en cliquant sur le bouton Image en haut à droite de la réponse qui te semble la plus pertinente.