Writing a script to check for callbacks in a list of files set in files.txt like this:
But it isn't working. Somehow it doesn't read the line, for example for the file 'file1.php', the same as a normal string 'file1.php' (check the loop in the following script checking whether any of the files in the list = 'file1.php' ( which SHOULD be the case, as when I output the array it is, but it seems to see a difference between the 'file1.php' read from the file using file_get_contents and read from the string ( script self )):file1.php
file2.php
Thanks in advance,Code:<?php
$files_list = "files.txt";
$handle = file_get_contents($files_list);
$files = explode("\n", $handle);
if($files[0] == "file1.php") {
echo "Yay";
}else{
echo $files[0]; //<--- this outputs 'file1.php' lol...
}
$calback_pattern[0] = "mail\((.*)\);";
$callbacks = array();
foreach($files as $file) {
$filename = $file;
echo "<p>Checking {$filename}(".filesize($filename).")...</p>";
//$handle2 = fopen($file, "r");
//$cont = fread($handle2, filesize($filename));
foreach($callback_pattern as $pattern) {
if(preg_match("/".$pattern."/",$cont,$matches))
$callbacks[$file] = $matches[0];
}
}
echo "<h2>Callbacks found:</h2>";
foreach($callbacks as $filename => $callback) {
echo "<div>in <b>{$filename}</b> <p> <pre>{$callback}</pre> </div>";
}
?>
Cheers.
EDIT: the problem seems to be with the array, this doesn't work for example:
Code:$files = "file1.php
file2.php";
$files = explode("\n", $files);
if($files[0] == "file1.php") { //is not true somehow o_O
echo "Yay"; //no yay shown
}
Works fine for me?
Try using strcmp rather than == to compare the strings.Code:[~]# cat test.php
<?php
$files = "file1.php
file2.php";
$files = explode("\n", $files);
if($files[0] == "file1.php") { //is not true somehow o_O
echo "Yay"; //no yay shown
}
?>
[~]# php test.php
Yay
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks