Vlearns
asked on
PHP directory navigation
Hi
Can some one help me achieve the following in php
this is what to do.
1) give my php program a directory where there are a bunch of php files.
2) taking each of these files at a time, i want to run php -l against it so that i can catch if there are any syntax errors in the file.
3)I want to print out the names of the files for which php -l failed and maybe send an email
pseudo code
1. go to dir
2. for all files in dir do
php -l filename.php
3. if php -l failed log the name of the file in a report or send an email right away.
Can some one help me achieve the following in php
this is what to do.
1) give my php program a directory where there are a bunch of php files.
2) taking each of these files at a time, i want to run php -l against it so that i can catch if there are any syntax errors in the file.
3)I want to print out the names of the files for which php -l failed and maybe send an email
pseudo code
1. go to dir
2. for all files in dir do
php -l filename.php
3. if php -l failed log the name of the file in a report or send an email right away.
To make it send an email ... (untested).
<?php
$s_Location = isset($argv[1]) && strlen($argv[1]) > 0 ? $argv[1] : '.';
$s_Errors = '';
foreach(new DirectoryIterator($s_Location) as $o_Entry) {
if ('.php' == strtolower(substr($o_Entry, -4))) {
if ('No syntax errors detected in ' . $o_Entry !== ($s_Error = exec('\php\php.exe -l ' . $o_Entry))) {
$s_Errors .= $s_Error, PHP_EOL;
}
}
}
mail('me@work.com', 'PHP lint failures', $s_Errors);
Ha! I said untested!
<?php
$s_Location = isset($argv[1]) && strlen($argv[1]) > 0 ? $argv[1] : '.';
$s_Errors = '';
foreach(new DirectoryIterator($s_Location) as $o_Entry) {
if ('.php' == strtolower(substr($o_Entry, -4))) {
if ('No syntax errors detected in ' . $o_Entry !== ($s_Error = exec('\php\php.exe -l ' . $o_Entry))) {
$s_Errors .= $s_Error . PHP_EOL;
}
}
}
mail('me@work.com', 'PHP lint failures', $s_Errors);
ASKER
Hi
thanks for your post,
still trying to figure it out, i introduced some php files with errors and it sent me just an email
with subject "php lint errors, is there a way i can get the name of the files for which it failed?
thanks for your post,
still trying to figure it out, i introduced some php files with errors and it sent me just an email
with subject "php lint errors, is there a way i can get the name of the files for which it failed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot, that really helped!!!!
ASKER
thanks a million!!!
You can run it with or without a path as the first and only parameter.
It requires PHP5 (for the SPL DirectoryIterator).
If no path is supplied, the current path is used.
Open in new window