Utilisation de la fonction preg_replace() pour trouver lien tout type pour une e

Résolu
wizard512 Messages postés 459 Date d'inscription dimanche 9 janvier 2005 Statut Membre Dernière intervention 11 mai 2013 - 1 août 2006 à 13:50
wizard512 Messages postés 459 Date d'inscription dimanche 9 janvier 2005 Statut Membre Dernière intervention 11 mai 2013 - 1 août 2006 à 15:50
Bonjour,
je souhaiterais récolter tous les liens,
ayant comme extention de fichier 'txt',
avec les protocols suivants :

        * http
        * http
        * ftp

Je m'explique voici un exemple :

  - le texte :
    
    "<li>fichier0
     <li>fichier1
     <li>fichier2
     <li>fichier3
     <li>fichier4
     <li>fichier5
     <li>fichier6
     <li>[fichier7
     <li>[newsfichier8"

  - les liens trouver parmit le texte :
       "http://domain/fichier0.txt"
       "http://domain/fichier1.txt"
       "http://domain/fichier2.txt"
       "http://domain/fichier3.txt"
       "http://domain/fichier4.txt"
       "http://domain/fichier5.txt"
       "http://domain/fichier6.txt"

Les liens trouver dans le texte seront classer
dans un tableau :
 
     - $tab = Array(
                      "http://domain/fichier0.txt",
                      "http://domain/fichier1.txt",
                      "http://domain/fichier2.txt",
                      "http://domain/fichier3.txt",
                      "http://domain/fichier4.txt",
                      "http://domain/fichier5.txt",
                      "http://domain/fichier6.txt"
                    );

Et Je souhaiterais qu'il soit fait grâce a la fonction
preg_replace() sauf que voila, cette fonction est ma bête noir, je ne peux pas la bléré  ^^'
J'y comprent rien a cette fonction...
Donc je solicite votre aide pour m'aider svp           
Merci....

       ~~ DotWizard512 ~~

2 réponses

malalam Messages postés 10839 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 2 mars 2010 25
1 août 2006 à 14:03
Hello,

déjà, ce sera avec preg_match_all et pas avec preg_replace.
Ensuite, un truc du genre (à optimiser hein) :
<?php
$sString = <<<HTML
<li>[fichier0>
<li>[fichier1>
<li>[fichier2>
<li>[fichier3>
<li>[fichier4>
<li>[fichier5>
<li>[fichier6>
<li>[fichier7>
<li>[fichier8>
<li>[fichier8>
HTML;


preg_match_all ([mailto:'@((http://|https://|ftp://).[^"]+(\.txt))+@' '@((http://|https://|ftp://).[^"]+(\.txt))+@'], $sString, $aRes);


echo '', print_r ($aRes[1]), '

';
?>
3
wizard512 Messages postés 459 Date d'inscription dimanche 9 janvier 2005 Statut Membre Dernière intervention 11 mai 2013 2
1 août 2006 à 15:50
Merci  ;)
0
Rejoignez-nous