php - Stuck with file_get_contents

290

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

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

    $file = @file_get_contents('http://ftvgirlsbay.com/design/tables/gals.txt');
    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]);
    }
    //print_r($thumbs);
    $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);
    shuffle($range);
    //print_r($range);
?>
<table align=center>
<?php
    $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";
            $num++;
        }
        echo '</tr>'."\r\n";
    }
?>
</table>

Result of this script: "More data needed. You have 1, you need 96!" ( http://ftvgirlsbay.com/random_scripts/test.php )

If this part

$file = @file_get_contents('http://ftvgirlsbay.com/design/tables/gals.txt');

change to

$file = @file_get_contents('http://sexsticker.info/ftvgirlsbay.com/pictable/gals.txt');

it works just fine

( http://ftvgirlsbay.com/random_scripts/test2.php )

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

629

Answer

Solution:

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?

Source

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.