Hi, Saturday, January 24, 2004, 1:00:10 AM, you wrote: JJM> [newbie, please help]
JJM> I'm trying to extract all URLs mentionning sound files from blocks of texts. JJM> I first tried with ereg and the following code works fine : JJM> $texte='TEST FIND<br>\net voici un fichier son JJM> http://serveur/repertoire/fichier.gig ou JJM> ftp://serveur/repertoire/fichier.snd et JJM> ftp://serveur/repertoire/fichier.mp3 la suite JJM> http://serveur/repertoire/fichier.wav de mon texte'; JJM> if JJM> (ereg("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", JJM> $texte, $regs)) { JJM> echo $regs[0]."<br>\n"; JJM> } JJM> else JJM> { JJM> echo "pas trouvé<br>\n"; JJM> } JJM> the only problem is that it will only extract the first URL, so I did a JJM> small modification to use preg_match_all : JJM> if JJM> (preg_match_all("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", JJM> $texte, $matches)) { JJM> for ( $i=0 ; $i < count($matches[0]) ; $i++ ) { JJM> echo $matches[0][$i]."<br>\n" ; JJM> } JJM> } else { JJM> echo "pas trouvé<br>\n"; JJM> } JJM> but I have the following error message : *Warning*: Unknown modifier JJM> '+' in *e:\program files\easyphp1-7\www\test_ereg.php3* on line *4* JJM> where line 4 is the line with the regular expression after preg_match_all JJM> What's that ? preg_* functions needs delimiters for the expression like '/<expression>/' or if there are likely to be / in the text you can use others like '!<expression>!' Its also a good idea to use single quotes so the expression gets ignored by php -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php