Supra Man
Supra Man

Reputation: 85

fgets not seeing new line

my simple php code

<?

error_reporting(E_ALL);

set_time_limit(0);
ini_set('show_errors', 1);
$file = "ftpfile.txt";
$handle = fopen($file, "r");
if(!filesize($file)>0) {
        echo "File is empty!";
    }
    else {
    while (($ftpservers = fgets($handle, 4096)) !== false) {

        echo $ftpservers. "\n\r";

    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);






        }
?>

my textfile

ftp.server:username:password    
ftp.server:username:password    
ftp.server:username:password    
ect..

running this code returns this

ftp.server:username:passwordftp.server:username:passwordftp.server:username:password
ect..

why is fgets returning the textfile in spades of three?

Upvotes: 1

Views: 368

Answers (2)

space ranger
space ranger

Reputation: 422

just an guess but are you sure the source file contains no spaces between ftp.server:username:password and the next entry?

Upvotes: 0

Gung Foo
Gung Foo

Reputation: 13558

There is a note about problems with line endings on the fgets() documentation page:

If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem.

Upvotes: 1

Related Questions