Read in text file line by line php - newline not being detected

 

I have a php function I wrote that will take a text file and list each line as its own row in a table.

The problem is the classic "works fine on my machine", but of course when I ask somebody else to generate the .txt file I am looking for, it keeps on reading in the whole file as 1 line.  When I open it in my text editor, it looks just as how I would expect it with a new name on each line, but its the newline character or something throwing it off.

So far I have come to the conclusion it might have something to do with whatever text editor they are using on their Mac system.

Does this make sense? and is there any easy way to just detect this character that the text editor is recognizing as a new line and replace it with a standard one that php will recognize?

UPDATE: Adding the following line solved the issue.

ini_set('auto_detect_line_endings',true);

 

Function:

function displayTXTList($fileName) {

    if(file_exists($fileName)) {

        $file = fopen($fileName,'r');

        while(!feof($file)) {

            $name = fgets($file);

            echo('<tr><td align="center">'.$name.'</td></tr>');

        }

        fclose($file);

    } else {

        echo('<tr><td align="center">placeholder</td></tr>');

    }      

}

转载于:https://www.cnblogs.com/weaver1/archive/2012/05/14/2500722.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值