lastChild; // no 'getDocumentElement' in PHP $k = 0; //number of students/marks $s = 0; //total $studs = $start->getElementsByTagName("student"); foreach( $studs as $stud ) { $n_name = $stud->getElementsByTagName("name")->item(0); $n_mark = $stud->getElementsByTagName("mark")->item(0); $the_name = $n_name->firstChild->wholeText; $the_mark = $n_mark->firstChild->wholeText; echo "$the_name 's mark is $the_mark\n"; $s += $the_mark; $k++; } if( $k == 0 ){ die("empty data"); }else{ return $s/$k; } }// average_2 function reading ($fichIn){ $doc = new DOMDocument(); $doc->load($fichIn); $moy = average_2($doc); echo "\nAverage : $moy\n"; }//reading reading($argv[1]); ?>