Page 1 of 1
php recursive regular expression headache
Posted: Sat Oct 11, 2003 11:06 am
by bongfish
Posted: Sat Oct 11, 2003 5:27 pm
by Gen-ik
It would probably make life a lot sweeter if you changed the way your URL part of the code was put together. For example instead of using
http://www.foo.com/dir[1-5]/image[01-05].jpg you would use
http://www.foo.com/?dirstart=1&dirend=5 ... imageend=5
That way PHP will instantly know where to start and stop.
This might work but I'm typing it now so you will need to test it.
Code: Select all
<?php
$ds = $_GET["dirstart"];
$de = $_GET["dirend"];
$is = $_GET["imagestart"];
$ie = $_GET["imageend"];
$links = array();
for($i=$ds; $i<=$de; $i++)
{
for($ii=$is; $ii<=$ie; $ii++)
{
if($ii<10)
{
$thisimage = "0".$ii;
}
else
{
$thisimage = $ii;
}
$links[] = "http://www.foo.com/dir{$i}/image{$thisimage}.jpg";
}
}
unset($i);
unset($ii);
// that should give you an array full of links. now chuck 'em onto the page
$linkcount = count($links);
for($i=0; $i<$linkcount; $i++)
{
echo '<img src="{$links[$i]}">';
}
?>
Hope that helps.
Posted: Sat Oct 11, 2003 7:14 pm
by bongfish
Posted: Sat Oct 11, 2003 9:35 pm
by McGruff
Can you pm me the url to your site. If it's what I think it is please don't post it on the board.
Posted: Sat Oct 11, 2003 11:45 pm
by bongfish
Posted: Sun Oct 12, 2003 7:05 am
by JAM
Edited:
More than enough to learn from... But no...
Posted: Sun Oct 12, 2003 10:47 am
by bongfish
Posted: Sun Oct 12, 2003 11:06 am
by JAM
Edited:
More than enough to learn from... But no...
Posted: Sun Oct 12, 2003 11:57 am
by bongfish
Posted: Sun Oct 12, 2003 1:01 pm
by m3rajk
1: do not link to possible examples that cause several pages to pop up. not everyone is surfing on mozilla and other nice browsers 100% of the time.
2: do not send us places that try to reset stuff.
i'm sure that problaby stopped some ppl right there.
moving on., there's a few good books on regexp by oreilly press. if you think you're going to use them more than here, then instead of waiting for us to help you more, it's advisable that you help yourself by getting one for a reference book.
now, before we can move from waht JAM gave you, which you state has the basics of what you're looking for, we need to know what the circumstances are with expected and unexpected results. we don't need the exacts, just examples. until then the best we can do is guess that you have issues when it's not called "dir" so why not make this into a bit more of a regexp instead of a test string? (which those books would make you be able to do on your own, but for the sake of speed i'll do now)
regexp="%^http://(\w+\.)?\w+\.(com|org|net)/[\w/]+/\w.(jpg|jpeg|jpe)$%i";
in this case, it's using perl
% is the delimiter
i makes it case insensitive
^ means it has to start with http://
$ means it has to end with a jpg extension
\w+\. means it can have any number of characters in the range [A-Za-z0-9_] followedby a period. the first being in () with ? means this works on foo.com as well as anything one level under (ie: me.foo.com or you.foo.com)
i will exaplain more if you feel you need it. but with the repitious nature of this i feell it should be obvious
Posted: Sun Oct 12, 2003 3:04 pm
by McGruff
You have made hints about the content of your site. I'm not going to jump to conclusions but I would like to look into this. You have not yet pm'd me as I requested.