php fgetcsv 函数
fgetcsv
( PHP 4中, PHP 5中)
fgetcsv -获取线从文件指针和解析为的CSV领域
描述
阵列fgetcsv (资源$处理[摘要$长度[ ,字符串$定界符[ ,字符串$附文[ ,字符串$逃生] ] ] ] )
类似fgets ( ) ,但fgetcsv ( )解析行读取的领域以CSV格式并返回一个数组包含字段读取。
参数
把柄
一个有效的文件指针到文件成功打开fopen ( )函数, popen ( )或fsockopen ( ) 。
长度
必须大于最长线(在字符)中可以找到的CSV文件(允许尾随线年底字符) 。它成为可选PHP 5中。省略此参数(或设置为0在PHP 5.0.4及更高版本)的最大行的长度不限,这是略为放缓。
定界符
集的字段分隔符(只有一个字符) 。默认值为一个逗号。
文
集外地文字符(一个字符只) 。默认为双引号。
逃生
设置转义字符(一个字符只) 。默认值为反斜杠( )
返回值
返回一个数组包含索引的字段读取。
注:一个空白行的CSV文件将返回一个数组组成一个单一的空场,并不会被视为一个错误。
注:如果PHP没有正确认识到行结尾时,无论是阅读文件或创建的Macintosh电脑,使auto_detect_line_endings运行时配置选项可能有助于解决这个问题。
fgetcsv ( )返回FALSE的错误,包括档案结尾。
修改
版本说明
5.3.0越狱参数增加
4.3.5 fgetcsv ( )现在是二进制安全
4.3.0附件参数增加
实例
例如# 1读取和打印的全部内容CSV文件
$row = 1;
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "
$num fields in line $row:
n";$row++;
for ($c=0; $c echo $data[$c] . "
n";
}
}
fclose($handle);
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
