C'est compliqué mais en gros je remplace toutes les images portant le src en question pour afficher à la place un iframe avec X paramètres.
C'est assez compliqué à expliquer mais je pense avoir bien expliqué ce dont je voulais faire.
Une regex m'aurait vraiment suffit, enfin je pense.
Voici le code que m'a donné codesrc:
1 2 3 4 5 6 7 8 9 10
| $a = <<<SC
<img src="image/miniature/laphoto2.jpg" alt='la photo' />
<img style='width:100px;' src="image/miniature/laphoto.jpg" alt='la photo' />
<img style='border:1px solid;height:50px;' src="image/miniature/laphoto.jpg" alt='la photo' />
SC;
$src = 'image/miniature/laphoto.jpg';
preg_match_all('#(<img.*src="'.$src.'".*/>)#im', $a, $matches);
print_r($matches[0]); |
En fait il presque parfait !:p
Il faudrait juste que chaque balise img trouvé soient dans une cellule différentes du tableau matches.
Car là, si dans ma variable j'ai:
"toto <img height='100' src='image/miniature/laphoto.jpg' /> blabla <img alt='laphoto' src='image/miniature/laphoto.jpg' style='width:130px;' /> titi"
Il va me mettre dans matches[0] ceci:
<img height='100' src='image/miniature/laphoto.jpg' /> blabla <img alt='laphoto' src='image/miniature/laphoto.jpg' style='width:130px;' />
Alors que j'aurai voulu avoir:
1 2
| matches[0]="<img height='100' src='image/miniature/laphoto.jpg' />"
matches[1]="<img alt='laphoto' src='image/miniature/laphoto.jpg' style='width:130px;' />" |
C'est plus claire ?
Partager