|
Posted by Janwillem Borleffs on 03/11/06 17:14
kennyjjohnson@gmail.com wrote:
> I am trying to find a script that will make php pages based on the
> file names.
> chevy_car_commercial.php
>
> And also dump that variable title
> Chevy Car Commercial into the <title> of the web page...
>
Using PHP 4.3 or better? Then you could try the following script:
<?php
$ext = 'mp3';
$path = '/path/to/*.mpeg';
$outdir = '.';
$glob = glob($path);
foreach ($glob as $file) {
$file = basename($file);
$fname_noext = preg_replace("/\.$ext$/", '', $file);
$title = ucwords(str_replace('_', ' ', $fname_noext));
$fname = $outdir . '/' . strtolower($fname_noext) . '.php';
$html = "<html>\n\t<head>\n\t\t<title>$title</title>\n\t";
$html .= "</head>\n\t<body></body>\n</html>";
if (!$fp = @fopen($fname, 'w')) {
print "Unable to create $fname. ";
print "Please check the permissions of '$outdir'\n";
continue;
} else {
fputs($fp, $html);
fclose($fp);
print "Successfully created $fname\n";
}
}
?>
When using PHP v < 4.3, replace the call to the glob function with
opendir/readdir (see the manual).
JW
[Back to original message]
|