Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

splfileobject.fputcsv(3) [php man page]

SPLFILEOBJECT.FPUTCSV(3)						 1						  SPLFILEOBJECT.FPUTCSV(3)

SplFileObject::fputcsv - Write a field array as a CSV line

SYNOPSIS
public int SplFileObject::fputcsv (array $fields, [string $delimiter = ","], [string $enclosure = '"'], [string $escape = " DESCRIPTION
Writes the $fields array to the file as a CSV line. PARAMETERS
o $fields - An array of values. o $delimiter - The optional $delimiter parameter sets the field delimiter (one character only). o $enclosure - The optional $enclosure parameter sets the field enclosure (one character only). o $escape - The optional $escape parameter sets the escape character (one character only). RETURN VALUES
Returns the length of the written string or FALSE on failure. Returns FALSE, and does not write the CSV line to the file, if the $delimiter or $enclosure parameter is not a single character. ERRORS
/EXCEPTIONS An E_WARNING level error is issued if the $delimiter or $enclosure parameter is not a single character. CHANGELOG
+--------------+-------------------------------+ | Version | | | | | | | Description | | | | +--------------+-------------------------------+ |5.5.21, 5.6.5 | | | | | | | Added the $escape parameter. | | | | +--------------+-------------------------------+ EXAMPLES
Example #1 SplFileObject::fputcsv example <?php $list = array ( array('aaa', 'bbb', 'ccc', 'dddd'), array('123', '456', '789'), array('"aaa"', '"bbb"') ); $file = new SplFileObject('file.csv', 'w'); foreach ($list as $fields) { $file->fputcsv($fields); } ?> The above example will write the following to file.csv: aaa,bbb,ccc,dddd 123,456,789 """aaa""","""bbb""" SEE ALSO
fputcsv(3), SplFileObject::fgetcsv. PHP Documentation Group SPLFILEOBJECT.FPUTCSV(3)

Check Out this Related Man Page

SPLFILEOBJECT(3)							 1							  SPLFILEOBJECT(3)

The SplFileObject class

INTRODUCTION
The SplFileObject class offers an object oriented interface for a file. CLASS SYNOPSIS
SplFileObject SplFileObjectextends SplFileInfoRecursiveIteratorSeekableIterator Constants o const integer$SplFileObject::DROP_NEW_LINE1 o const integer$SplFileObject::READ_AHEAD2 o const integer$SplFileObject::SKIP_EMPTY4 o const integer$SplFileObject::READ_CSV8 Methods o public SplFileObject::__construct (string $filename, [string $open_mode = "r"], [bool $use_include_path = false], [resource $con- text]) o public string|array SplFileObject::current (void ) o public bool SplFileObject::eof (void ) o public bool SplFileObject::fflush (void ) o public string SplFileObject::fgetc (void ) o public array SplFileObject::fgetcsv ([string $delimiter = ","], [string $enclosure = " o public string SplFileObject::fgets (void ) o public string SplFileObject::fgetss ([string $allowable_tags]) o public bool SplFileObject::flock (int $operation, [int &$wouldblock]) o public int SplFileObject::fpassthru (void ) o public int SplFileObject::fputcsv (array $fields, [string $delimiter = ","], [string $enclosure = '"'], [string $escape = " o public string SplFileObject::fread (int $length) o public mixed SplFileObject::fscanf (string $format, [mixed &$...]) o public int SplFileObject::fseek (int $offset, [int $whence = SEEK_SET]) o public array SplFileObject::fstat (void ) o public int SplFileObject::ftell (void ) o public bool SplFileObject::ftruncate (int $size) o public int SplFileObject::fwrite (string $str, [int $length]) o public void SplFileObject::getChildren (void ) o public array SplFileObject::getCsvControl (void ) o public int SplFileObject::getFlags (void ) o public int SplFileObject::getMaxLineLen (void ) o public bool SplFileObject::hasChildren (void ) o public int SplFileObject::key (void ) o public void SplFileObject::next (void ) o public void SplFileObject::rewind (void ) o public void SplFileObject::seek (int $line_pos) o public void SplFileObject::setCsvControl ([string $delimiter = ","], [string $enclosure = " o public void SplFileObject::setFlags (int $flags) o public void SplFileObject::setMaxLineLen (int $max_len) o public void SplFileObject::__toString (void ) o public bool SplFileObject::valid (void ) Inherited methods o public SplFileInfo::__construct (string $file_name) o public int SplFileInfo::getATime (void ) o public string SplFileInfo::getBasename ([string $suffix]) o public int SplFileInfo::getCTime (void ) o public string SplFileInfo::getExtension (void ) o public SplFileInfo SplFileInfo::getFileInfo ([string $class_name]) o public string SplFileInfo::getFilename (void ) o public int SplFileInfo::getGroup (void ) o public int SplFileInfo::getInode (void ) o public string SplFileInfo::getLinkTarget (void ) o public int SplFileInfo::getMTime (void ) o public int SplFileInfo::getOwner (void ) o public string SplFileInfo::getPath (void ) o public SplFileInfo SplFileInfo::getPathInfo ([string $class_name]) o public string SplFileInfo::getPathname (void ) o public int SplFileInfo::getPerms (void ) o public string SplFileInfo::getRealPath (void ) o public int SplFileInfo::getSize (void ) o public string SplFileInfo::getType (void ) o public bool SplFileInfo::isDir (void ) o public bool SplFileInfo::isExecutable (void ) o public bool SplFileInfo::isFile (void ) o public bool SplFileInfo::isLink (void ) o public bool SplFileInfo::isReadable (void ) o public bool SplFileInfo::isWritable (void ) o public SplFileObject SplFileInfo::openFile NULL ([string $open_mode = "r"], [bool $use_include_path = false], [resource $context]) o public void SplFileInfo::setFileClass ([string $class_name = "SplFileObject"]) o public void SplFileInfo::setInfoClass ([string $class_name = "SplFileInfo"]) o public void SplFileInfo::__toString (void ) PREDEFINED CONSTANTS
o SplFileObject::DROP_NEW_LINE -Drop newlines at the end of a line. o SplFileObject::READ_AHEAD -Read on rewind/next. o SplFileObject::SKIP_EMPTY -Skips empty lines in the file. This requires the READ_AHEAD flag be enabled, to work as expected. o SplFileObject::READ_CSV -Read lines as CSV rows. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.9 | | | | | | | | | | SplFileObject::SKIP_EMPTY value changed to 4. | | | Previously, value was 6. | | | | +--------+---------------------------------------------------+ PHP Documentation Group SPLFILEOBJECT(3)
Man Page