00001 <?php
00015 define('EXAMPLES_DIR','/home/saurabh/Desktop/courses/2011/monsoon/scripting_and_computer_environment/lectures/source_code/11-php/11-php-examples');
00016
00017
00021 define('BASE_URL','http:
00022
00023
00024
00031 function read_example_dir()
00032 {
00033 global $example_array;
00034
00035
00036 $example_dir = opendir(EXAMPLES_DIR);
00037 if($example_dir == false)
00038 {
00039 die('Cannot open dir ' . EXAMPLES_DIR . ' for reading');
00040 }
00041
00042 $example_count=0;
00043
00044
00045 $current_file=readdir($example_dir);
00046 while($current_file != false)
00047 {
00048 if($current_file != '.' && $current_file != '..' && is_dir($current_file))
00049 {
00050 $example_array[$example_count]=$current_file;
00051 $example_count++;
00052 }
00053 $current_file=readdir($example_dir);
00054 }
00055
00056
00057
00058 closedir($example_dir);
00059
00060
00061 if($example_count > 1)
00062 sort($example_array, SORT_STRING);
00063 }
00064
00065
00066
00073 function display_index_page()
00074 {
00075 global $example_array;
00076
00077
00078
00079 read_example_dir();
00080
00081 ?>
00082 <html>
00083 <head>
00084 <title>PHP examples</title>
00085 </head>
00086 <body>
00087 <h3>PHP examples:</h3>
00088 <ul>
00089 <?php
00090
00091
00092
00093 $limit=count($example_array);
00094
00095
00096 for($counter1=0; $counter1<$limit; $counter1++)
00097 {
00098 echo '<li><a href="' . BASE_URL . $example_array[$counter1] . '">' .
00099 $example_array[$counter1] . '</a></li>' . "\n";
00100 }
00101 ?>
00102 </ul>
00103 </body>
00104 </html>
00105 <?php
00106 }
00107
00108
00109
00115 function main()
00116 {
00117
00118 display_index_page();
00119 }
00120
00121
00122
00123
00124 main();
00125 ?>