I'm trying to extract all URLs mentionning sound files from blocks of texts.
I first tried with ereg and the following code works fine :
$texte='TEST FIND<br>\net voici un fichier son http://serveur/repertoire/fichier.gig ou ftp://serveur/repertoire/fichier.snd et ftp://serveur/repertoire/fichier.mp3 la suite http://serveur/repertoire/fichier.wav de mon texte';
if (ereg("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", $texte, $regs)) {
echo $regs[0]."<br>\n";
}
else
{
echo "pas trouvé<br>\n";
}
the only problem is that it will only extract the first URL, so I did a small modification to use preg_match_all :
if (preg_match_all("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", $texte, $matches)) {
for ( $i=0 ; $i < count($matches[0]) ; $i++ ) { echo $matches[0][$i]."<br>\n" ; } } else { echo "pas trouvé<br>\n"; }
but I have the following error message : *Warning*: Unknown modifier '+' in *e:\program files\easyphp1-7\www\test_ereg.php3* on line *4*
where line 4 is the line with the regular expression after preg_match_all
What's that ?
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php