Closed Thread
Results 1 to 2 of 2

Thread: File_get_contents problem

  1. #1
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    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.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Warning: file_get_contents() [function.file-get-contents]
    By Bioshox in forum PHP Development
    Replies: 1
    Last Post: 09-22-2011, 03:13 AM
  2. If problem or cout problem?
    By chaoticape in forum C and C++
    Replies: 4
    Last Post: 06-10-2011, 10:29 AM
  3. WAMP file_get_contents($url) problem
    By hhheng in forum PHP Development
    Replies: 3
    Last Post: 03-17-2010, 04:03 PM
  4. HELP! - file_get_contents
    By maros174 in forum PHP Development
    Replies: 2
    Last Post: 03-02-2010, 02:45 AM
  5. Replies: 0
    Last Post: 04-26-2007, 05:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts