Expressions régulières
vetofish
Messages postés
3
Date d'inscription
Statut
Membre
Dernière intervention
-
Max -
Max -
Bonjour,
je souhaite mettre en pratique l'insertion d'images dans l'annuaire DMOZ, grace aux services de [URL=http://www.thumbshots.org/dynamicintegration.pxf]http://www.thumbshots.org/dynamicintegration.pxf[/URL]
Je ne parviens pas à extraire toutes les URL (appelée [LINK] dans l'exemple) et les noms des URL (appelée [ALT]) dans une liste de ce type :
[CODE]
texte variable
<li><a href="[LINK1]">[ALT1]</a> - texte variable
<li><a href="[LINK2]">[ALT2]</a> - texte variable
<li><a href="[LINK3]">[ALT3]</a> - texte variable
texte variable
[/CODE]
(un tiret "6" entouré de deux blancs, entre </a> et texte variable)
Puis remplacer :
[CODE]
<li><a href="[LINK1]">[ALT1]</a>
[/CODE]
par :
[CODE]
<table border="0" cellpadding="3" cellspacing="0" width="130" height="100" align="left"><tr><td align="center" valign="middle">
<img src="about:blank" width="1" height="1" border="0">
<script language="javascript">
if (window.OTP_TSCreate)
OTP_TSCreate('http://www.thumbshots.org[LINK1]', '[LINK1]', '[TARGET]', '[ALT1]');
</script>
<noscript>
<a href="[LINK1]" target="[TARGET]"><img src="http://www.thumbshots.org[LINK1]" border="0"></a>
</noscript>
</td></tr></table>
<a href="[LINK1]">[ALT1]</a>
[/CODE]
idem pour LINK2, LINK3 ... autant qu'il y a de lignes dans la liste de départ.
Merci de votre aide.
je souhaite mettre en pratique l'insertion d'images dans l'annuaire DMOZ, grace aux services de [URL=http://www.thumbshots.org/dynamicintegration.pxf]http://www.thumbshots.org/dynamicintegration.pxf[/URL]
Je ne parviens pas à extraire toutes les URL (appelée [LINK] dans l'exemple) et les noms des URL (appelée [ALT]) dans une liste de ce type :
[CODE]
texte variable
<li><a href="[LINK1]">[ALT1]</a> - texte variable
<li><a href="[LINK2]">[ALT2]</a> - texte variable
<li><a href="[LINK3]">[ALT3]</a> - texte variable
texte variable
[/CODE]
(un tiret "6" entouré de deux blancs, entre </a> et texte variable)
Puis remplacer :
[CODE]
<li><a href="[LINK1]">[ALT1]</a>
[/CODE]
par :
[CODE]
<table border="0" cellpadding="3" cellspacing="0" width="130" height="100" align="left"><tr><td align="center" valign="middle">
<img src="about:blank" width="1" height="1" border="0">
<script language="javascript">
if (window.OTP_TSCreate)
OTP_TSCreate('http://www.thumbshots.org[LINK1]', '[LINK1]', '[TARGET]', '[ALT1]');
</script>
<noscript>
<a href="[LINK1]" target="[TARGET]"><img src="http://www.thumbshots.org[LINK1]" border="0"></a>
</noscript>
</td></tr></table>
<a href="[LINK1]">[ALT1]</a>
[/CODE]
idem pour LINK2, LINK3 ... autant qu'il y a de lignes dans la liste de départ.
Merci de votre aide.
3 réponses
-
on m'a dit d'utiliser la fonction explode, mais je ne sais pas comment faire ?
-
c'est impossible ?
-
C'est facile mon ami, essaie ca:
if (preg_match('/<li><a href="(.+?)">(.+?)<\/a>/i', $Ligne, $Matches)) { $LINK = urlencode($Matches[1]); $ALT = $Matches[2]; $Code = "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"130\" height=\"100\" align=\"left\"><tr> <td align=\"center\" valign=\"middle\"><img src=\"about:blank\" width=\"1\" height=\"1\" border=\"0\"> <script language=\"javascript\"> if (window.OTP_TSCreate)OTP_TSCreate(\"http://www.thumbshots.org$LINK\", \"$LINK\", \"\", \"$ALT\"); </script> <noscript><a href=\"$LINK\" target=\"\"><img src=\"http://www.thumbshots.org$LINK\" border=\"0\"></a></noscript> </td></tr></table><a href=\"$LINK\">$ALT</a>"; $Ligne = preg_replace('/<li>.+?<\/a>/i', $Code, $Ligne); }
Ca marche pour mon site! Les Thumbshots sont vraiment cool!
-- Max