note 88773 added to function.str-getcsv

From: Date: Fri, 06 Feb 2009 23:32:20 +0000
Subject: note 88773 added to function.str-getcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-150324@lists.php.net to get a copy of this message
Drawing inspiration from daniel dot oconnor at gmail dot com, here's an alternative str_putcsv() that leverages existing PHP core functionality (5.1.0+) to avoid re-inventing the wheel. <?php if(!function_exists('str_putcsv')) { function str_putcsv($input, $delimiter = ',', $enclosure = '"') { // Open a memory "file" for read/write... $fp = fopen('php://temp', 'r+'); // ... write the $input array to the "file" using fputcsv()... fputcsv($fp, $input, $delimiter, $enclosure); // ... rewind the "file" so we can read what we just wrote... rewind($fp); // ... read the entire line into a variable... $data = fgets($fp); // ... close the "file"... fclose($fp); // ... and return the $data to the caller, with the trailing newline from fgets() removed. return rtrim( $data, "\n" ); } } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 67.130.135.29 ---- Manual Page -- http://www.php.net/manual/en/function.str-getcsv.php Edit -- https://master.php.net/note/edit/88773 Del: integrated -- https://master.php.net/note/delete/88773/integrated Del: useless -- https://master.php.net/note/delete/88773/useless Del: bad code -- https://master.php.net/note/delete/88773/bad+code Del: spam -- https://master.php.net/note/delete/88773/spam Del: non-english -- https://master.php.net/note/delete/88773/non-english Del: in docs -- https://master.php.net/note/delete/88773/in+docs Del: other reasons-- https://master.php.net/note/delete/88773 Reject -- https://master.php.net/note/reject/88773 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150324) next »