php - Stuck with file_get_contents


guys. Please help me to find out the problem. I have one script on my site:

    define('C', 16); // NUMBER OF ROWS
    define('D', 6); // NUMBER OF CELLS

    $file = @file_get_contents('');
    if($file === FALSE) { 
        echo "<h2>Make file gals.txt with data!</h2>";
        return FALSE; 
    $file = explode("\r\n", $file);
    $thumbs = array();
    while(list(,$el) = each($file)) {
        $el = explode('|', $el);
        if(isset($el[0]) && isset($el[1]))
            $thumbs[] = array($el[0], $el[1]);
    $size = sizeof($thumbs);
    if($size < C*D) {
         echo "<h2>More data needed. You have $size, you need ".C*D."!</h2>";
         return FALSE;

    $range = range(0, $size - 1);
<table align=center>
    $num = 0;
    for($i = 0; $i < C; $i++) {
        echo '<tr align=center>'."\r\n";
        for($k = 0; $k < D; $k++) {
            echo '<td><a href="'.$thumbs[$range[$num]][1].'">FTV '.$thumbs[$range[$num]][0].' Gallery</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>'."\r\n";
        echo '</tr>'."\r\n";

Result of this script: "More data needed. You have 1, you need 96!" ( )

If this part

$file = @file_get_contents('');

change to

$file = @file_get_contents('');

it works just fine

( )

So if I links to the .txt file on my server's side script reads only 1 line. If I links to the .txt on the remote server - script works wilh all lines




I figured out your problem and was able to replicate the issue.

The issue is with the\r in

$file = explode("\r\n", $file);

Remove the\r

$file = explode("\n", $file);

Both servers might be different. One may be on a Linux, while the other on a Windows server.

People are also looking for solutions to the problem: php - How to add functions to a MVC Joomla component to access data from a different table?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.