php recursive regular expression headache

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bongfish
Forum Newbie
Posts: 5
Joined: Sat Oct 11, 2003 11:06 am

php recursive regular expression headache

Post by bongfish »

Last edited by bongfish on Sat Oct 18, 2003 11:56 pm, edited 2 times in total.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
User avatar
bongfish
Forum Newbie
Posts: 5
Joined: Sat Oct 11, 2003 11:06 am

Post by bongfish »

Last edited by bongfish on Sat Oct 18, 2003 11:58 pm, edited 1 time in total.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
bongfish
Forum Newbie
Posts: 5
Joined: Sat Oct 11, 2003 11:06 am

Post by bongfish »

Last edited by bongfish on Sat Oct 18, 2003 11:58 pm, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Edited:
More than enough to learn from... But no...
Last edited by JAM on Sun Oct 12, 2003 5:02 pm, edited 1 time in total.
User avatar
bongfish
Forum Newbie
Posts: 5
Joined: Sat Oct 11, 2003 11:06 am

Post by bongfish »

Last edited by bongfish on Sat Oct 18, 2003 11:58 pm, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Edited:
More than enough to learn from... But no...
Last edited by JAM on Sun Oct 12, 2003 5:02 pm, edited 1 time in total.
User avatar
bongfish
Forum Newbie
Posts: 5
Joined: Sat Oct 11, 2003 11:06 am

Post by bongfish »

Last edited by bongfish on Sat Oct 18, 2003 11:58 pm, edited 1 time in total.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply