title: Count entries in a XML file
body: <p>Is there a way to count how many entries there are in a given xml file?</p>
  
  <p>Example: <a href="http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/rackemup420/cars?output=xml" rel="nofollow">http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/rackemup420/cars?output=xml</a></p>
  
  <p>My Code:</p>
  
  <pre><code>// The POST URL and parameters      
  $request =  'http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/driver/'.$u.'/cars?output=xml';      
  
  // Get the curl session object      
  $session = curl_init($request);      
  
  // Set the POST options.  
  curl_setopt($session, CURLOPT_HEADER, true);      
  curl_setopt($session, CURLOPT_RETURNTRANSFER, true);      
  
  // Do the POST and then close the session      
  $response = curl_exec($session);      
  curl_close($session);      
  
  // Get HTTP Status code from the response      
  $status_code = array();      
  preg_match('/\d\d\d/', $response, $status_code);      
  
  // Check for errors      
  switch( $status_code[0] ) {      
      case 200:      
          // Success      
          break;      
      case 503:      
          die('Service unavailable. An internal problem prevented us from returning data to you.');      
          break;      
      case 403:      
          die('Forbidden. You do not have permission to access this resource, or are over your rate limit.');      
          break;      
      case 400:      
          // You may want to fall through here and read the specific XML error      
          die('Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.');      
          break;      
      default:      
          die('Your call returned an unexpected HTTP status of:' . $status_code[0]);      
  }      
  
  // Get the XML from the response, bypassing the header      
  if (!($xml = strstr($response, '&lt;?xml'))) {      
      $xml = null;      
  }      
  
  // Output the XML      
  
  $worldCar = simplexml_load_string($xml);     
  foreach ($worldCar-&gt;worldCar as $cars)        
  {    
  
      $playercarid = $cars['carId'];      
      $playercarmake = $cars['make'];      
      $playercarname = $cars['carName'];   
  
          $playercaraccel = $cars-&gt;physicsProfile['acceleration'];      
          $playercarhandle = $cars-&gt;physicsProfile['handling'];      
          $playercarrating = $cars-&gt;physicsProfile['rating'];  
          $playercarspeed = $cars-&gt;physicsProfile['topSpeed'];  
          $playercartier = $cars-&gt;physicsProfile['tier'];  
  }  
  </code></pre>