Etienne Kneuss

home » repository » php » php.net » script-skel.php
Tree:
school
mp3
php
sample
publications
Math_Derivative
Math_Expression
ircbot
php.net
docweb
lsb
check-acronyms.php
spam_tickets.sql.txt
spam-protection.php
genphpt.php
fix-whitespace.php
generrorlinks.php
remove-ordie.php
docbkphp.vim
script-skel.php
cvslogger.php
generateCvslogs.php
images
dump

Source code raw phps

    <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: +----------------------------------------------------------------------+ | PHP Documentation Site Source Code                                   | +----------------------------------------------------------------------+ | Copyright (c) 1997-2005 The PHP Group                                | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license,      | | that is bundled with this package in the file LICENSE, and is        | | available at through the world-wide-web at                           | | http://www.php.net/license/3_01.txt.                                 | | If you did not receive a copy of the PHP license and are unable to   | | obtain it through the world-wide-web, please send a note to          | | license@php.net so we can mail you a copy immediately.               | +----------------------------------------------------------------------+ | Authors: Etienne Kneuss <colder@php.net>                             | +----------------------------------------------------------------------+ $Id: script-skel.php,v 1.1 2007/01/18 21:29:59 colder Exp $ */ if (PHP_SAPI !== 'cli') {     echo "This script is ment to be run under CLI\n";     exit(1); } // This regex will be used to filter files. The content of each file will get // tested against this regex. You can then process these files only. define('FILTER_REGEX', '/./'); if ($_SERVER['argc'] == 2 &&       in_array($_SERVER['argv'][1], array('--help', '-help', '-h', '-?'))        ||        $_SERVER['argc'] < 2) {     // Put the description of your script here.     echo "<Description>\n\n";     echo "Usage:      {$_SERVER['argv'][0]} <path>\n";     echo "            --help, -help, -h, -?      - to get this help\n";     die; } // Ensure the trailing / $fullpath_dir = rtrim($_SERVER['argv'][1], '/').'/'; if (!is_dir($fullpath_dir)) {     echo "ERROR: ($fullpath_dir) is not a directory.\n";     exit(1); } // Start processing $log = array('errors'    => array(),              'rewritten' => array()); $rrit = new RecursiveIteratorIterator(new RecursiveRegexIterator(new RecursiveDirectoryIterator($fullpath_dir), FILTER_REGEX)); // This array contains directories that will be ignored. You don't need // to specify . and .. as it will already be handled by DirectoryIterator. $ignore_dirs = array('CVS'); foreach($rrit as $file) {     var_dump($file->getFilename());     if ($file->isWritable() && $file->isFile()) {         // Filter some exts         $ext = pathinfo($file->getFilename(), PATHINFO_EXTENSION);         $modified = false;         $content = file_get_contents($file->getPath().'/'.$file->getFilename());         // Process         //          // You'll have to affect the files in this section, don't forget         // switch $modified to true if the curent file required a          // modification. It will get rewritten and logged correctly.         // Save afected file:         if ($modified) {             $content = file_put_contents($file->getPath().'/'.$file->getFilename(), $content);             $log['rewritten'][] = $file->getPath().'/'.$file->getFilename();         }     } else {         $log['errors'][] = 'Unable to access '.$file->getPath().'/'.$file->getFilename();     } } echo count($log['rewritten'])." file(s) have been affected.\n"; if (!empty($log['errors'])) {     echo count($log['errors'])." error".(count($log['errors']) > 1 ? 's' : '')." occured:\n";     foreach($log['errors'] as $error) {         echo " $error\n";     } } exit(count($log['errors']) > 0);

Comments

There is currently no comment here.

Add a comment

Username:

Spam Challenge: 12+14=?

Comment: