Jump to content

File_get_contents problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
Writing a script to check for callbacks in a list of files set in files.txt like this:

Quote

file1.php
file2.php

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 )):

<?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>";

}


?>

Thanks in advance,

Cheers.

EDIT: the problem seems to be with the array, this doesn't work for example:

$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

}


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Works fine for me?
[~]# 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

Try using strcmp rather than == to compare the strings.