Re: preg_match_all : not all regular expressions ?

From: Date: Mon, 26 Jan 2004 12:46:56 +0000
Subject: Re: preg_match_all : not all regular expressions ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-175749@lists.php.net to get a copy of this message
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&eacute;<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&eacute;<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

« previous php.general (#175749) next »