>From reading that code it would seem you've got a series of XML files (the outer while loop) each containing an unknown number of entries (the foreach loop and counter), however I can't see $next being reset anywhere inside the loop, so IF you had less then 10 objects in the file it would run once and die when "$next == $last".

In you case with more then 10 entries it runs once over the first file and stops because it has more then 10. From the logic in your description however it sounds like you are wanting different then foreach on the inner loop.

Is this line:
"foreach ($xml as $entry)" where the real work occurs? I haven't even got a php runtime on this PC (and I've been writing java an python for week, so forgive stuff-ups) so I can't test but, I think you want pseudo-code something like:

$length = $xml.length();
for ($i = 0; i < 10 && $i < $length; $i++) {
    $entry = $xml[$i];
    // Do stuff

On 17 February 2010 05:23, Osullivan L. <L.Osullivan@swansea.ac.uk> wrote:

Hi Folks,


I’m trying to get a script to work in order to pull some vcard information from an xml document but have come up against a php quirk for which I can’t find a solution. I was wondering if anyone had any suggestions.


I am trying to get the script to finish after the first 10 “person” entries for testing but the while loop doesn’t appear to evaluate $v until the foreach loop which increments it is complete. The while loop is therefore actually stopping when $v = 100 as there are 100 entries per xml file;   


Here’s some of the code:


    $v = 0;

    $endloop = false;


while($endloop == false && $v < 10) {


        $xml = simplexml_load_file($next);


                    if($xml && $next != $last) {


                    foreach ($xml->link as $link) {

                        $attributes = $link->attributes();

                        if($attributes->rel == "next") {

                            $last = $attributes->href;




                    foreach ($xml as $entry) {

                        $id = (string)$entry->id;

                        $vparse = new Contact_Vcard_Parse();

                        $cardinfo = $vparse->fromText($entry->content);


                        $persons[$v] = array('id' => $id,

                                                               'firstname' => ucfirst(strtolower($cardinfo['0']['N'][0]['value']['given'][0])),

                                                               'lastname' => ucfirst(strtolower($cardinfo['0']['N'][0]['value']['family'][0])));








                else {


                    $endloop = true;







Luke O'Sullivan
Library Systems Officer - Virtual Academic Library
South West Wales Higher Education Partnership (SWWHEP)
Tel: 01792 602772
Website: www.swwhep.ac.uk

Ffôn: 01792 602772
Gwefan: www.swwhep.ac.uk

Check out the new SWWHEP Online GreenGuide at:


SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
Vufind-tech mailing list