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_buil d.$var."/");
}
//FOR ALPHA build($dir_buil d);
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($fil e); // 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($fi leList)){
sort ($fileList); // sort the file list in the array
reset ($fileList); // go back to the top of the array
closedir($handl e);
}
}
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($handle 2))) {
if ($file2 != "." && $file2 != ".." && (strstr($file2, '.txt'))) {
$file2 = strtolower($fil e2); // make all filenames lowercase (looks better. can be removed)
$fileList2[] = substr(trim($fi le2),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($fi leList2)){
sort ($fileList2); // sort the file list in the array
reset ($fileList2); // go back to the top of the array
closedir($handl e2);
}
}
if(is_array($fi leList) && is_array($fileL ist2)){
$not_made = array_diff($fil eList, $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($lett er2) || !$letter2){
$letter2 = "0-9";
}
$fh = fopen($dir.$val ue.".txt", 'w') or die("can't open file");
$value2 = ucwords(str_rep lace("."," ", $value));
$stringData = "My Data Here";
fwrite($fh, $stringData);
fclose($fh);
echo $dir.$value."<b r />";
unset($value2); // break the reference with the last element
}
}
}
?>[/PHP]
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_buil d.$var."/");
}
//FOR ALPHA build($dir_buil d);
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($fil e); // 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($fi leList)){
sort ($fileList); // sort the file list in the array
reset ($fileList); // go back to the top of the array
closedir($handl e);
}
}
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($handle 2))) {
if ($file2 != "." && $file2 != ".." && (strstr($file2, '.txt'))) {
$file2 = strtolower($fil e2); // make all filenames lowercase (looks better. can be removed)
$fileList2[] = substr(trim($fi le2),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($fi leList2)){
sort ($fileList2); // sort the file list in the array
reset ($fileList2); // go back to the top of the array
closedir($handl e2);
}
}
if(is_array($fi leList) && is_array($fileL ist2)){
$not_made = array_diff($fil eList, $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($lett er2) || !$letter2){
$letter2 = "0-9";
}
$fh = fopen($dir.$val ue.".txt", 'w') or die("can't open file");
$value2 = ucwords(str_rep lace("."," ", $value));
$stringData = "My Data Here";
fwrite($fh, $stringData);
fclose($fh);
echo $dir.$value."<b r />";
unset($value2); // break the reference with the last element
}
}
}
?>[/PHP]
Comment