I understand that when writing text to a file using php, a plus sign gets converted to a space, unless the text is encoded. However, I cannot see how to apply such encoding to my specific example.
I am using the following php script (called from javascript via AJAX) to write an array as a csv file. The array is converted into a string with “” as column separators as “<XX>” as line feed separators. The code works perfectly, except when an array cell text includes a plus sign (“+”). When writing to disk, the php script changes the plus signto a space.
For example, the original two cells started with: c+d=e and A+B=c.
This was converted to a string (for php): "Row=c+d=e<XX>A+B=c&Fname=test.csv".
However, the resulting csv only contains: "c d=e","A B=c","
"
Below is the php script being used:
`<?php
if(isset($_POST["Row"])){
$rlist = $_POST["Row"];
$fname =($_POST["Fname"]);
$rArray = explode("~",$rlist);
$totalR = count($rArray);
$fp = fopen($fname, 'w');
for($i =0; $i<$totalR;$i++){
$row = $rArray[$i];
$srow =explode("<XX>",$row);
array_push($srow,"\n");
fputcsv($fp,$srow);
}
fclose($fp);
}
?>
`
How can I “encode” the text so that this does not happen and the resulting csv contains the plus signs?