在php中读取csv文件
我想逐行读取 csv 文件。我已经编写了代码,但它以加密方式给出输出。我的代码是
$row = 1;
$handle = fopen($_FILES['csv']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000,",")) != FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
I want to read a csv file line by line. i have written code but it give output in encrypted manner . my code is
$row = 1;
$handle = fopen($_FILES['csv']['tmp_name'], "r");
while (($data = fgetcsv($handle, 1000,",")) != FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里,我提交一些示例代码来从 csv 文件读取数据。
该代码应该适合您,即使在使用该代码之后,如果您仍然面临加密文本的问题,那么我认为文档字符编码格式会出现一些问题。
here I am submitting some sample code to read data from a csv file.
This code should work for you, even after using this code if still you face problem with encrypted text then I think there would be some problem with document character encoding format.
这与 PHP
fgetcsv()
文档中的示例 #1 基本完全相同。检查您的输入文件,因为这里实际上没有任何内容可以“加密”数据。如果文件采用外来字符集编码,并且您在 ISO-8859 上输出,那么您将获得“加密”输出。This is basically exactly the same as example #1 in the PHP
fgetcsv()
docs. Check your input file, as there's nothing really in here that would "encrypt" data. If the file's encoded in a foreign character set, and you're outputting on ISO-8859, then you will get "encrypted" output.