Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Write comma to csv file

Tags:

php

csv

I've got a form which submits data to a csv file. When a user inputs a comma to a field, it destroys my csv structure. I want to convert inputted commas so that they can get displayed as a character.

I tried this:

$_POST["field"] = str_replace(",", "','", $_POST["field"]);
like image 733
coder Avatar asked Jan 08 '23 11:01

coder


1 Answers

Use html encoding for instant relief , but still my recommendation to use phpExcel

$comma="&#44";
$_POST["field"] = str_replace(",", $comma, $_POST["field"]);
like image 85
Rohit Kumar Avatar answered Jan 15 '23 21:01

Rohit Kumar