+ Reply to Thread
Results 1 to 2 of 2

Thread: File_get_contents problem

  1. #1
    Programmer webcodez is an unknown quantity at this point webcodez's Avatar
    Join Date
    Feb 2010
    Posts
    127

    File_get_contents problem

    Writing a script to check for callbacks in a list of files set in files.txt like this:

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

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

    }


    ?>
    Thanks in advance,

    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



  2. #2
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,843
    Blog Entries
    25

    Re: File_get_contents problem

    Works fine for me?
    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
    Try using strcmp rather than == to compare the strings.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. HELP! - file_get_contents
    By maros174 in forum PHP Forum
    Replies: 2
    Last Post: 03-02-2010, 02:45 AM
  2. Replies: 0
    Last Post: 04-26-2007, 04:33 PM