473,396 Members | 2,033 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,396 software developers and data experts.

Remove last row from csv file using PHP

Is it possible to remove the last row of the downloaded csv file, and the removed row will gets added in next sheet. May I know is this possible in PHP. As I searched in google and I didnt find any solutions.
Jun 14 '19 #1
2 8526
gits
5,390 Expert Mod 4TB
what exactly do you mean with 'next sheet' - removing a line from a file is relatively easy and could be done in different ways - personally i would probably use the file-method so i would have the lines in an array already. now you can do with it whatever you want - like deleting the original file and write all except the last line back to a file and then put the last line wherever you want to.

PS: note - it will split the lines at newline characters - so if the values in a csv line contain such then it might be necessary to use another method like fgetcsv or such.
Jun 14 '19 #2
Vanisha
25 16bit
To remove the last row from a CSV file using PHP, you can use the following steps:

Open the CSV file for reading and writing using the fopen() function.
Use the fseek() function to move the file pointer to the end of the file.
Use the fgets() function to read the last line of the file.
Use the ftruncate() function to truncate the file to remove the last line.
Close the file using the fclose() function.
If you want to learn any technologies, join CETPA Infotech.
Mar 21 '23 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Venkat | last post by:
Hi All, Currently i guess rename and remove are not supported using fstream. How do i rename or remove a file? regards, Venkat
2
by: Paul LAURENT | last post by:
Hi everybody, I am using the STL "ofstream" class. I open a file using "ofstream" in update at the end mode ("ate"), I can read and write my file correctly. => What I would like to do is...
3
by: syntax | last post by:
hi, i want to read a file using fread() in equal chunks through a for loop so that at the last call i dont get error..which way, i should read it? let me give an example, suppose i have 100...
1
by: Kishor | last post by:
Hi, I have developed an assembly, now it the the time to build the setup for assembly. I have created Setup project. I have added necessary files, created shortcuts... etc. when I started build,...
2
by: lekshminair | last post by:
dears can u help me remove last letter in a string. eg: arises in this string remove only last 's' ouput:arise
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
8
by: =?Utf-8?B?Q2hyaXMgRmluaw==?= | last post by:
I am trying to make a minor modification to the code below and need some assistance. Currently this code is using the java.util, java.util.zip, and java.io assemblies from the vjslib.dll assembly....
13
by: SuvarnaChaudhari | last post by:
Hi,I am new to .net. As per ur guidance I tried myString = myString.SubString(0,myString.Length-1); I also used str.lastindexof n str.remove,but by using this I m gettin string as ' (B193 '' H13 ''...
9
by: josh64057 | last post by:
I am trying to remove the last character using a query in access 2010. I only want to remove the last character if the lenght is 7 characters. If i use Left(,Len()-1). I end up removing both "T" from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.