I've got my php working to count the number of rows in the full csv document, but trying to get a number of rows that have data in them in a particular column. Is this possible with PHP?
我已经让我的php工作来计算完整csv文档中的行数,但是尝试在特定列中获取包含数据的行数。这可能用PHP吗?
$fp = file('test.csv');
echo count($fp);
1 个解决方案
#1
You can use fgetcsv
function and check in every row the data.
您可以使用fgetcsv函数并检查每一行数据。
For example if you want to check how many rows have data in the second column, run that.
例如,如果要检查第二列中有多少行包含数据,请运行该行。
$data_found = 0;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle))
{
if ($data[1] != '')
{
// check the data specifically in the second column
$data_found ++;
}
}
echo 'Rows with data in the second column:'.$data_found;
#1
You can use fgetcsv
function and check in every row the data.
您可以使用fgetcsv函数并检查每一行数据。
For example if you want to check how many rows have data in the second column, run that.
例如,如果要检查第二列中有多少行包含数据,请运行该行。
$data_found = 0;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle))
{
if ($data[1] != '')
{
// check the data specifically in the second column
$data_found ++;
}
}
echo 'Rows with data in the second column:'.$data_found;