473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

fgetcsv() on string?

Hi!
I get CSV-data from a post-request. How can I work on that?
Currently I save the data to a temp-file, then read it back with
fgetcsv and then delete the temp-file. That works, but I don't really
like it ...
Is there a way to directly parse the CSV data from the string (with
php-4.2.4)

Thanks for your answers!
Jul 17 '05 #1
2 6328
Joe Randstein <ja*******@hotmail.com> wrote:
I get CSV-data from a post-request. How can I work on that?
Currently I save the data to a temp-file, then read it back with
fgetcsv and then delete the temp-file. That works, but I don't really
like it ...
Is there a way to directly parse the CSV data from the string (with
php-4.2.4)


IMHO this could easily be done with split/explode/preg_split (which are
in the see also section of fgetcsv)

--

Daniel Tryba

Jul 17 '05 #2
ja*******@hotmail.com (Joe Randstein) wrote in message news:<f7**************************@posting.google. com>...
Hi!
I get CSV-data from a post-request. How can I work on that?
Currently I save the data to a temp-file, then read it back with
fgetcsv and then delete the temp-file. That works, but I don't really
like it ...
Is there a way to directly parse the CSV data from the string (with
php-4.2.4)


IMHO, that is the most dependable way. Put the operation in a function
like:
<?php
function ParseCSVString($str, $delim=',')
{
//write the CSV string to a temporary file so that fgetcsv() can be
used to process...
$fp = tmpfile();
fwrite($fp, $str);
rewind($fp); //rewind to process CSV
$csv_length = strlen($str);
$data_arr = fgetcsv($fp, $csv_length, $delim);
fclose($fp); //clean up temp file
return $data_arr; //return the array
}
?>

_or_ use the csv_explode() function found at the usernotes of
<http://in2.php.net/explode> Hope, my version will do the work
properly.

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
2
by: Stephen Preston | last post by:
I have an xls worksheet I wish to export as a text or csv file to import with fgetcsv() The 'save as' function on excell lets me save as a comma separated value or tab delimited text files....
1
by: Jonaed | last post by:
This is my code: $handle = fopen ($file, "r"); $c = 1; while (($values_list = fgetcsv ($handle, 1000, ',', '"')) !== FALSE) { echo $c . "<br>\n"; $c = $c +...
0
by: tjonsek | last post by:
I am working with directories in PHP for the first time. I have code that I've changed multiple times to try different things. I would think this is pretty standard fare so I'm not sure why I can't...
0
by: et | last post by:
fgetcsv() do unwanted "left trim" on fields started with locale characters (code page win-1250). Problem persist only if local character is first character in field for example, let say that C...
5
by: mantrid | last post by:
I am using fopen() and fgetcsv() to open an excel file and extract data for upload to mysql database. The doesnt seem to be a parameter in either of these functions for ommitting the first row of...
3
by: jrrdnx | last post by:
I have a form set up to allow someone to upload a .csv and populate its data into a database using the fgetcsv() function. All of the code works fine because everything in the .csv file is populated...
2
code green
by: code green | last post by:
I am trying to skip empty rows in a csv file The manual states But none of these tests seem to work. Anybody know why while(($data = fgetcsv($this->handle)) !== false) { ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.