Logo  

CS479/579 - Web Programming II

Displaying ./code/PHP/simple/loops.php

<?php
  $data = file_get_contents("/etc/passwd");
  $rows = explode("\n", $data);

  // foreach($rows as $row) or:
  foreach($rows as $key => $row) {
    if ($row == "") break;
    list($username, $passwd, $uid, $gid, $gecos, $home, $shell) = explode(":", $row);
    echo $username . ":" . $gecos . "\n";
  }
?>