Tag Archives: csv

Remove Line From CSV File

Questions: I have .csv file with 4 columns. What’s the easiest way to remove a line identical with the id of the first column? Here’s where I got stuck: if($_GET[‘id’]) { $id = $_GET[‘id’]; $file_handle = fopen(“testimonials.csv”, “rw”); while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle, 1024); if ($id == $line_of_text[0]) { // remove row }… Read More »

Force Download CSV File

Questions: I am trying to create a button that will force a CSV file download but for some reason I am not able to get it working. This is the code that I have: public function export_to_csv($result) { $shtml=””; for ($i=0; $i<count($result); $i++){ $shtml = $shtml.$result[$i][“order_number”]. “,” .$result[$i][“first_name”]. “,” .$result[$i][“middle_name”]. “,” .$result[$i][“last_name”]. “,” .$result[$i][“email”]. “,”… Read More »

Forcing fputcsv to Use Enclosure For *all* Fields

Questions: When I use fputcsv to write out a line to an open file handle, PHP will add an enclosing character to any column that it believes needs it, but will leave other columns without the enclosures. For example, you might end up with a line like this 11,”Bob “,Jenkins,”200 main st. USA “,etc Short… Read More »

Load and read a csv file with php

Questions: I want to download some content in csv format. It is stored online in a csv file. I can not just read the content. I first have to download the file, open and then read it. Is there a way to open it directly? Or do I have to first load/upload it on my… Read More »

Combining 2 CSV files

Questions: I’m trying to combine two CSV files in PHP. I’m looking for perfect method. Here’s my code so far: $one = fopen(‘data5.csv’, ‘r’); $two = fopen(‘userdata.csv’, ‘r’); $final = fopen(‘final_data.csv’, ‘a’); $temp1 = fread($one, filesize(“data5.csv”)); $temp2 = fread($two, filesize(“userdata.csv”)); fwrite($final, $temp1); fwrite($final, $temp2); Answers:

Save CSV files into mysql database

Questions: I have a lot of csv files in a directory. With these files, I have to write a script that put their content in the right fields and tables of my database. I am almost beginner in php language : I have found some bits of code on the Internet. It seems to work,… Read More »

Regular expression for parsing CSV in PHP

Questions: I already managed to split the CSV file using this regex: “/,(?=(?:[^\”]\”[^\”]\”)(?![^\”]\”))/” But I ended up with an array of strings that contain the opening and ending double quotes. Now I need a regex that would strip those strings of the delimiter double quotes. As far as I know the CSV format can encapsulate… Read More »

How to import csv file in PHP?

Questions: I am very new to web development. In fact, I am just starting to learn. Can somebody please give a complete but very simple example on how to import CSV file in PHP? I tried the one I got from the internet but I’m very confused because it’s complicated for me. I am using… Read More »