Questions tagged [fgetcsv]
fgetcsv() is a PHP function which parses the line it reads for fields in CSV format and returns an array containing the fields read.
487
questions
-1
votes
1
answer
26
views
Using fgetcsv to replace commans within numbers
I have the following CSV data:
"Symbol","Name","Trade Volume","Trade Value","UIN Settlement Volume ","UIN Settlement Value ","UIN ...
0
votes
1
answer
63
views
Combine/move one column from CSV to another CSV as last column
I'm having two CSV files. The first one contains two columns (comma separated) the second one contains just one column.
I'm trying to combine them and move the column from the second file as a last ...
0
votes
0
answers
15
views
Prepared Statements php array from csv into mysql [duplicate]
New to prepared statements, trying to insert php array into database with mysqli.
if(isset($_FILES['upload'])) {
if (($handle = fopen($_FILES['upload']['tmp_name'], '...
0
votes
0
answers
56
views
Behavior of fgetcsv through SplFileObject is not the same from PHP 8.0 to 8.1 - how to stay backwards compatible?
I have something like that in my code, which is working well since a few years :
$spl_file = new SplFileObject($file_path, 'r', false, null);
$spl_file->setFlags(SplFileObject::READ_CSV | ...
0
votes
1
answer
30
views
how to have checking on date on csv upload PHP
$ayear=date("Y") + 1 ;
$lyear=date("Y") - 1 ;
$cyear=date("Y") ;
some code here
fgetcsv($handle);
while($data=fgetcsv($handle)){
$item0=($...
-2
votes
1
answer
597
views
PHP fopen or file_get_contents reading CSV files with fgetcsv
I have a issue. In my original code I opened a file with:
$file = fopen ("files/bla1.exp" , "r" );
And after opening the file, I want to read the CSV line by line with:
$aCsvLine ...
-1
votes
1
answer
236
views
How to use fgetcsv() when the CSV has several double quotes """" or if the entire line is wrapped in quotes?
Some CSV files that we import to our server cannot be parsed correctly.
We are reading the CSV file with PHP's fgetcsv():
while (($line = fgetcsv($file)) !== false) { ... }
However, when the CSV line ...
0
votes
1
answer
133
views
Should I use "fgetcsv" instead of "array_map" and how to do it?
I've made this script to extract data from a CSV file.
$url = 'https://flux.netaffiliation.com/feed.php?maff=3E9867FCP3CB0566CA125F7935102835L51118FV4';
$data = array_map(function($line) { return ...
0
votes
1
answer
257
views
Creating pages from a csv file
I've created a page that grabs data from a CSV (http://liamjken.com/aim-parse/aim-websites-new.csv) and displays it on this page http://www.liamjken.com/aim-parse/parse.php?17
?17 references the row ...
0
votes
2
answers
180
views
PHP import csv NULL for empty col
function upload_excel1 (){
global $conn;
$filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
ini_set(&...
-1
votes
1
answer
37
views
PHP Get accurate record count when importing csv
I have a function that inside my class that is handled 3 pieces of data.
filename to be parsed
replace string which is basically the insert or replace text except for the values.
the tablename to ...
0
votes
1
answer
44
views
How do I enclose a field with double quotes, using fgetcsv
I have this csv:
1629311007-1407,"[{""cats"":""Cat1""},{""cats"":""Cat2""}]",[],title
<?php
header('...
1
vote
1
answer
68
views
How to keep using the csv data even after the we lose access to the file?
Sorry if the title is confusing. Let me explain.
I have a function which displays the data in a csv file below.
<?php
function readCsv($filename, $header=false) {
$handle = fopen($filename, &...
0
votes
1
answer
354
views
Saving HTML table to CSV on server from client side
I'm trying to read a .dat file (it's a CSV with delimiter';') and convert it into a table and is done in PHP and is as follows:
<table id='sol'>
<?php
echo "<html><body>"...
0
votes
1
answer
335
views
Detect if a row read in by fgetcsv is the last row of the csv file with PHP 7.4
Is it possible to detect in the following code example if the current row is the last row? Here is my code:
$file = \fopen('/path/to/file.csv', 'rb');
while (($row = \fgetcsv($file, 0, ';')) !== false)...
0
votes
0
answers
213
views
Uploaded CSV file with 4 columns and NO header. Need to create array and assign a specific key value to each column
After 2+ hours looking through Stack Overflow for a solution, I'm now needing to ask for guidance. My inexperience may mean I just don't know how to "ask" the right question, but I haven't ...
0
votes
3
answers
661
views
fgetcsv encoding issue (PHP)
I am being sent a csv file that is tab delimited. Here is a sample of what I see:
Invoice: Invoice Date Account: Name Bill To: First Name Bill To: Last Name Bill To: Work Email Rate Plan Charge: ...
1
vote
0
answers
52
views
Get right delimiter CSV file php
I need to read a CSV file that is not mine. So sometimes the delimiter will be a semicolon and an another time it will be a comma. So I need to find a way to know which one will be the right delimiter....
0
votes
0
answers
51
views
fgetcsv(), delimiter is not being recognised
I am trying to use fgetcsv() to grab data from a CSV file to a HTML table.
I am able to put the data into the HTML table, but I would like the table to have two columns, and separated by a "|&...
0
votes
1
answer
136
views
Irish accent get changed to wiered charecter while processing the csv file in php (yii1.1 framework)
I know there are a lot of similar question has already been asked in this community but unfortunately nothing gonna work for me.
I have a CSV sheet which I need to import in our system. Sheet is ...
1
vote
0
answers
38
views
If Then Comparison not working? Different Text Type?
I'm completely lost right now on a simple if then check for php.
My current code is:
while ($row = fgetcsv($handle, 100000, ",")) {
if ($header === null) {
$header = $row;
...
-1
votes
2
answers
1k
views
Keep Integer and Float Types When Converting CSV Data to PHP Arrays With str_getcsv and fgetcsv
When using PHPs str_getcsv-function numbers will be treated as strings:
<?php
$csv = str_getcsv('0,1.2,"string"');
var_dump( $csv );
/* result: array(3) {
[0]=>string(1) "0"...
0
votes
1
answer
236
views
PHP fgetcsv with not valid CSV file
I have a CSV file with content:
Центральный;Московская область;117036;PC;JEEP;GRAND CHEROKEE;ДЖИП ГРАНД ЧЕРОКИ;В;01.01.0001;08.05.2014;2004;1J8G2Е8N94У161064;-;1J8G2Е8N94У161064;-;94;2;227;4701;1;...
0
votes
2
answers
1k
views
Update WooCommerce product stock from csv
Combining this topic Update WooCommerce product price and stock combined with fgetcsv and fopen
My goal is to update the stock of the products on a woocommerce website from a csv file. With help of ...
1
vote
1
answer
102
views
How to search a CSV file and return multiple entries based on keyword input
Hello I have a CSV file that has Name, Extension, and Cell. Some users have both extensions and a cell number. I am trying to create a search on our intranet page where a user will enter a keyword (...
1
vote
1
answer
650
views
How to concatenate two columns in a csv file in php?
I have a csv file like this:
I would like to concatenate the values of the style_color columns in this csv file. To have for example SCJEG4_1014.
I wrote a script, it creates this last column with ...
1
vote
1
answer
350
views
keep line breaks of csv datas
I'm using the kirby cms and some php to generate a text file from the datas of a csv file.
In the datas of my csv file, there are several paragraphs with line breaks into the text.
I need to keep ...
0
votes
2
answers
370
views
Using PHP mySQL with CSV data containing BOM
I have a database that holds stock levels for certain items that are supplied by different suppliers. Each supplier sends me a daily CSV file with their current stock levels. I am trying to update the ...
0
votes
1
answer
588
views
How to improve the speed of insertion of the csv data in a database in php?
I wrote this code that allows to read a folder, depending on the file name is inserted in a different table the data of the csv file. Once the file is processed it is moved to another folder.
My code ...
0
votes
1
answer
155
views
How to insert the first line of a csv file in a php database?
I have two csv files like, first csv file BI1_2020.csv like this:
391;FR-RC O/O HOSSEGOR MEN;07/21/2020;0021000002509;GR01-S8;8666-CLEAR;TU;1;15;12.5;0;EUR
391;EN-RC O/O HOSSEGOR MEN;07/21/2020;...
5
votes
1
answer
807
views
Reading > 1GB GZipped CSV files from external FTP server
In a scheduled task of my Laravel application I'm reading several large gzipped CSV files, ranging from 80mb to 4gb on an external FTP server, containing products which I store in my database based on ...
-1
votes
1
answer
146
views
Import of a CSV file into MySQL - database incomplete
I would like to update a database regularly by a CSV file. I have now thought about the following way:
I put the CSV file on the server, establish an SSH connection with Putty and start a php script, ...
1
vote
2
answers
284
views
How to improve the speed of a for loop in PHP?
I have a CSV file with different lines:
;0;1;0;4;5;M;468468;A1101;0090
0;1;0;4;5;M;468468;A1108;0090
And in a folder of photos that must have the naming format "A1101_0090-1.JPG" for the ...
0
votes
0
answers
228
views
Combine two CSV files by comparing row values and skip if there is no match
I have two CSV files.
The second file contains a lot more rows than the first file.
I only need the one's that match, and then create a final CSV file.
The zeros needs to be removed.
File 1 Example:
...
0
votes
0
answers
86
views
Can I upload CSV file to MySQL database without deleting "\" backslash which is placed in CSV file using php
Csv file has been uploaded to database but backslash() is automatically getting deleted when I upload CSV file to database.
I need that \ to be also uploaded in the database.
For eg : I need to add ...
0
votes
1
answer
566
views
Try getting data from CSV to insert in mysql using PHP, Read but it is not storing in the database
So I want to import data from CSV file which consist of
name, lastname, age
I have successfully import the data and also getting the data from each column but it for some reason didn't manage to ...
0
votes
2
answers
994
views
Why PHP Curl with a while loop produces a 504 Timeout?
Good day I'm trying to create some virtual cards with an array of json from a CSV file. The CSV file have 100 cards that I'm trying to create. If I try to post the full 100 lines in the csv file I ...
1
vote
0
answers
262
views
Importing CSV files in PHP when imported text contains bullet points
I have a simple code that imports CSV files ;
function readInputFromFile($file)
{
$fh = fopen($file, 'r');
while (!feof($fh))
{
$ln = fgetcsv($fh);
$ln = array_implode($ln);
...
1
vote
1
answer
172
views
How to exclude keys from a php multidimensional array?
I have a code that allows me to read a csv file like this:
REFERENCE;COLOR;QUANTITY;TURNOVER;SELL TROUGH;COMMENT
GJK0C9;8952;3;90;3%;Pack S
GJKCS4;399;2;19;10%;Windows
And that allows me to browse ...
0
votes
1
answer
213
views
How to display line by line a csv file in PHP with a particular structure? [closed]
I have this code that reads a csv file and displays it in this form :
REFERENCE;COLOR;QUANTITY;TURNOVER;SELL TROUGH;COMMENT
GJK0C9;8952;3;90;3%;Pack S
GJKCS4;399;2;19;10%;Windows
GSIJS5;9224;...
4
votes
3
answers
4k
views
How to parse a csv file that contains 15 million lines of data in php
I have a script which parses the CSV file and start verifying the emails. this works fine for 1000 lines. but on 15 million lines it shows memory exhausted error. the file size is 400MB. any ...
0
votes
2
answers
499
views
Why does fgetcsv() apparently sometimes treat "end of file" as an error?
From the manual at https://www.php.net/fgetcsv :
fgetcsv() returns NULL if an invalid handle is supplied or FALSE on other errors, including end of file.
Am I to interpret this as meaning that "...
-3
votes
1
answer
239
views
want to get the IDs from a CSV file having same values in other column in php
I want to get the IDs which are in first column of CSV file according to the values in second column having same data.
I mean if code is EF in csv then its IDs value should get 1,2,3,4,5 and so on for ...
0
votes
2
answers
815
views
PHP iterate through each row of csv and return row with matching element
I have a csv file called data.csv.
Here's a sample of what's in data.csv
Microsoft,2020-02-13,"Sample",tt,aa,qq,w,ee,rr,tt,", ",", ",", ","2020-02-13 16:03:08"
Google,2020-02-13,"HQ",tt,aa,qq,w,ee,...
0
votes
1
answer
107
views
Update price, status stock, post status form CSV (more 20k products) in WOOCOMMERCE (Memory runs out on 3000 products)
I use the construction for read csv file (about 25000 lines) in my method update() of my class
if(($handle = fopen($this->csv_url, 'r')) !== false) {
$row = 0;
while(($data = ...
0
votes
2
answers
902
views
CSV column values as variables in PHP
I have simple csv file:
id | ean
1 | 2342342345234
2 | 3453453454353
I want to have access for this data by variable in foreach loop:
$id = 1, $ean = 2342342345234
Is that possible?
<?php
$...
2
votes
2
answers
657
views
Incorrect String Length While Reading A CSV File Using PHP
I am reading a CSV file, line by line using following php code.
<?php
$temp=0;
$s="http://localhost/BulkMessage/Uploads/Number_Files/f7aa248e5fce52411723_CSV_7xxxxxxxx.csv";
try
{
$file = ...
0
votes
0
answers
101
views
Import (parse) large CSV file with php
I have large CSV file of the data which i need to import using php. CSV contains 50 000 plus rows and 12 columns. Size up to 10MB.
example of the csv:
1;B*2332IF2.8;Hikvision DS-2CD2332-I F2.8 DOME;...
0
votes
1
answer
558
views
Failed to read csv file from a server directory in PHP
In the server, there are some csv file. I want to get all the csv file in an array and then read the last updated csv file from the array. And then, I want to keep the last updated CSV data into an ...
0
votes
1
answer
26
views
Searching a file for multiple strings and output the data
How can I search a .tsv file for multiple matches to a string and export them to a database?
What I'm trying to do is search a large file called mdata.tsv (1.5m lines) for a string given to it from ...