我想逐行阅读,但我不想处理换行符,我希望将其删除,这样我最终只能得到该行的内容。
所以现在我的功能是:
function getProductCount($path)
{
$count = 0;
foreach (file($path) as $name) {
if($name == "<product>\n")
{
$count = $count + 1;
}
}
return $count;
}
但理想情况下我想做的是:
function getProductCount($path)
{
$count = 0;
foreach (file($path) as $name) {
if($name == "<product>")
{
$count = $count + 1;
}
}
return $count;
}
有没有办法也删除回车符?
谢谢
最佳答案
http://www.php.net/manual/en/function.file.php
查看可以添加到函数调用中的其他标志。您应该使用“FILE_IGNORE_NEW_LINES”
关于php - PHP 逐行读取时可以排除换行符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6915801/