Here is my code and what it does is create a page for every directory with the contents of choice.
Its been working on all letters except "u" I can't seem to figure it out.
Does someone see the flaw that I'm not seeing?
[PHP]<?php
$dir_build = "../data/pages/";
$inside = array("0-9","A","B","C","D","E","F","G","H","I","J","K","L" ,"M",
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z ");
foreach($inside as $var){
$var = strtolower($var);
build($dir_build.$var."/");
}
//FOR ALPHA build($dir_build);
function build($dir){
if ($handle = opendir($dir)) {
$filecount = "0"; //reset the number of files
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && (!strstr($file,'.txt'))) { // remove the move up directory commands. (. and ..)
$file = strtolower($file); // make all filenames lowercase (looks better. can be removed)
$fileList[] = trim($file); // add the file to an array so it can be sorted easily.
$filecount = $filecount + 1; //count the number of files
}
}
if(is_array($fileList)){
sort ($fileList); // sort the file list in the array
reset ($fileList); // go back to the top of the array
closedir($handle);
}
}
if ($handle2 = opendir($dir)) { // read the current directory. Change the "." to the directory you need.
$filecount2 = "0"; //reset the number of files
while (false !== ($file2 = readdir($handle2))) {
if ($file2 != "." && $file2 != ".." && (strstr($file2,'.txt'))) {
$file2 = strtolower($file2); // make all filenames lowercase (looks better. can be removed)
$fileList2[] = substr(trim($file2),0,-4); // add the file to an array so it can be sorted easily.
$filecount2 = $filecount2 + 1; //count the number of files
}
}
if(is_array($fileList2)){
sort ($fileList2); // sort the file list in the array
reset ($fileList2); // go back to the top of the array
closedir($handle2);
}
}
if(is_array($fileList) && is_array($fileList2)){
$not_made = array_diff($fileList, $fileList2);
}
echo "<br /><br />The following were made in $dir<br />";
if($not_made){
foreach ($not_made as $value) {
$letter2 = $value{0};
if(is_int($letter2) || !$letter2){
$letter2 = "0-9";
}
$fh = fopen($dir.$value.".txt", 'w') or die("can't open file");
$value2 = ucwords(str_replace("."," ", $value));
$stringData = "My Data Here";
fwrite($fh, $stringData);
fclose($fh);
echo $dir.$value."<br />";
unset($value2); // break the reference with the last element
}
}
}
?>[/PHP]