Hallo,
I've got the following code to get all the files in a dir and all the subdir's
<?php
function recursive_listdir($base) {
static $filelist = array();
static $dirlist = array();
if(is_dir($base)) {
$dh = opendir($base);
while (false !== ($dir = readdir($dh))) {
if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') {
$subbase = $base ."/". $dir;
$dirlist[] = $subbase;
$subdirlist = recursive_listdir($subbase);
} elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..') {
$filelist[] = $base ."/". $dir;
}
}
closedir($dh);
}
$array['dirs'] = $dirlist;
$array['files'] = $filelist;
//return $array; //This shows the dirs and the files
return $filelist; // This shows only all the files in the dirs
}
echo '<pre>';
print_r(recursive_listdir($home_dir));
echo '</pre>';
?>
The following code is to replace a string in a html file
<?
function replace($find, $replace, $file){
ob_start();
include($file);
$html = ob_get_contents();
ob_end_clean();
$html = str_replace("$find", "$replace", $html);
$fp = fopen($file, "r+" );
fwrite($fp, $html);
fclose($fp);
}
?>
Now a want to use the replace function in all listed html files resulted from the function recursive_listdir.
How do i do that?