Search code examples
phpls

PHP Beginner: Is using the exec command standard practice?


I am just starting php. I am just curious if there is a better way to do this. This displays all of my scripts in the same folder as this script.

I am not sure if it is standard to use the exec command. It does not seem very portable.

<html>
<head>
   <title>My PHP Practice Scripts</title>
</head>

<body>
   <center><h1>PHP Scripts</h1></center>
   <?php
      exec("ls -1 *.php", $output);

      foreach ($output as &$tmp){
         echo "<a href=\"$tmp\">$tmp</a><br>";
      }
   ?>
</body>
</html>

Solution

  • There are directory functions for such operations: http://www.php.net/manual/en/ref.dir.php