How to modify the csv file in php: first get the current absolute path; then read one line of content in the CSV each time, the code is [while ($data = fgetcsv($file))]; finally this is a Array, to get each data, just access the array subscript.
php method to modify the csv file:
php reads the csv file and processes it with the header as the key Array of names
header("Content-type: text/html; charset=GBK");//设置输出编码 ini_set('memory_limit', '1024M');//设置内存 set_time_limit(0); //设置超时 $dir = dirname(__FILE__).'/'; //获取当前绝对路径 $row = 1;//第一行开始 $file = fopen($dir.'5111.csv', "r"); # 结果 $res = array(); # 计数标示 $header = []; $flag = false; $i = 0; while ($data = fgetcsv($file)) {//每次读取CSV里面的一行内容 if (!$flag) { $header = $data;//此为一个数组,要获得每一个数据,访问数组下标即可 $flag = true; } else { $temp = array_slice($data, 0,11);//取多少列数据 foreach ($temp as $key => $value) { $index = $header[$key]; $res[$i][$index] = $value; } $i++; } } echo "<pre class="brush:php;toolbar:false">"; print_r($res); die;
Related learning recommendations:php programming(video)
The above is the detailed content of How to modify csv file in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
