Reply to Re: Create PHP pages from list of files in directory

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация