Forum Moderators: coopster

Message Too Old, No Replies

Multiple reg.exp. and a loop

         

look_at_me

6:21 pm on Mar 21, 2004 (gmt 0)

10+ Year Member



Hi!
I've worked out this code to grab stuff from a gallery website...

<?php
$content = strip_tags(implode("",file('http://ADDRESS/')),'<a><img>');
preg_match_all("/<a.*?href=\"(.+?)\".*?>(.+?)<\/a>/is",$content,$matches);

for ($i=0;$i<count($matches[0]);$i++) {
$txt = $matches[2][$i];
echo 'URL : '.$matches[1][$i].'<br>';
echo 'Text : '. $txt .'<br>';
preg_match("/(\d+) pics made by (.+)$/i",$txt,$out);
echo 'Pics : '. $out[1] .'<br>';
echo 'Author : '. $out[2] .'<br><br>';
}
?>

But the out array doesn't contain anything, nothing is written after "pics" and "author"...
Can you please tell me what i'm doing wrong?

look_at_me

1:25 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



Can't anybody answer me!? I really need help on this one... Do i need to rephrase?

nostra

4:42 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



imho there is no error

which string do you get in $txt?

look_at_me

4:21 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



$txt = "45 pics made by George";

Timotheos

4:49 pm on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I copy pasted your code and it worked for me.

<?php
$txt = "45 pics made by George";
preg_match("/(\d+) pics made by (.+)$/i",$txt,$out);
echo 'Pics : '. $out[1] .'<br>';
echo 'Author : '. $out[2] .'<br><br>';
?>

Output:

Pics : 45
Author : George

look_at_me

3:17 pm on Mar 25, 2004 (gmt 0)

10+ Year Member



Yeah, well it didn't work when it was in a loop. But it works now...