Can PHP exclude the newline character when reading line by line?

前端 未结 5 690
时光说笑
时光说笑 2021-01-15 05:50

I want to read line by line but I do not want to deal with newline, I want it to be removed so I only end up with the content of the line.

So right now my function i

5条回答
  •  感动是毒
    2021-01-15 06:05

    You can perform rtrim() on the line at the beginning of each loop iteration.

    function getProductCount($path)
    {
        $count = 0;
    
        foreach (file($path) as $raw_name) {
            $name = rtrim($raw_name);
            if($name == "")
            {
                $count = $count + 1;
            }
        }
        return $count;
    }
    

提交回复
热议问题