loop [foreach] construction in a seven-liner PHP-Script

dear community - good Morning!

i want to parse the site - and get the results out of it:

see this third overview-page

therefore i need to loop over the line 2 - don ´ i!?



 <?php
 $data = file_get_contents('http://www.educa.ch/dyn/79363.asp?action=search');
 $regex = '/Page 1 of (.+?) results/';
 preg_match($regex,$data,$match);
 var_dump($match);
 echo $match[1];
 ?>


in order to get the details of the pages -

see this first detail-page

see this second detail-page

see this third detail-page

just help me with this seven-liner :wink:

on a sidenote: measuring code in terms of how many lines it took to write is
a Perl-coder-attitude. Only Perl programmers care about that and i find it hard
it is to read Perl code.

i had a closer look at the PHP: foreach - Manual


foreach (array_expression as $value)
    statement
foreach (array_expression as $key => $value)
    statement

The first form loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one (so on the next loop, you'll be looking at the next element).The second form does the same thing, except that the current element's key will be assigned to the variable $key on each loop. As of PHP 5, it is possible to iterate objects too. 

can i do this like mentioned above!:
love to get some hints

If you are looping over a set of values, then supply it as an array. I would guess something like this.

foreach (array(4438,53,2939) as $id) {
  // $id takes successive values from the array here
  // do something
}

hello Ken_Yap

many thanks for the quick reply. Great to hear from you!

foreach (array(4438,53,2939) as $id) {
// $id takes successive values from the array here
// do something
}

as i am not sure which numbers which are filled with content - i therefore have to** loop from 1 to 10000**. So i make sure that i get all data.

What do you think!?

foreach (array( 1, to 10000) as $id) {
// $id takes successive values from the array here
// do something
}

is this the correct expression: -

foreach (array( 1, to 10000) as $id) { // $id takes successive values from the array here
// do something
}

In that case you should probably use the for statement, which you should be familiar with if you know C:

for ($i = 1; $i <= 10000; $i++) {
  // body of loop
}

http://www.php.net/manual/en/control-structures.for.php

The foreach is really for looping through arrays or objects. Perl is nicer in that it hides the details of the iterator from you. When you write in Perl:

for $i (1..10000) {
  # body
}

it doesn’t really create a 10000 element array.