Jump to content

[SOLVED] Using trim function to remove spaces in a line


jschofield

Recommended Posts

Hello all. I am trying to remove spaces in a line in a text file using the trim function. I am pretty sure it works but I am using it in the wrong way and not sure how to figure it out. Please help. Below is my script. It has an include script but that script is just for logging. Thanks for everyone's help.

Data:

0200,000970    ,LILY       

*Here it has a comma about 25 spaces after the name LILY. Those are the spaces I am looking to remove.

                                                                                                                                                                                                                                 

Script:

<?php

 

$inputfile = "C:/SMDIM/Data/allstu.TXT";

$outputfile = "C:/SMDIM/Data/Wisconsin_Student_Data.csv";

$logfilename = "C:/SMDIM/Logs/Wisconsin_Student_Log.txt";

include'C:/SMDIM/Translators/importlibrary.inc.php';

$count = 0;

//open the file

if(!$outfilefp = fopen($outputfile, "w")) {

wlogdie("Failed to open $outputfile");

}else{

wlog("Opened $outputfile for writing");

}

 

if(!$inputfp = fopen($inputfile, "r")) {

wlogdie("Failed to open $inputfile");

}else{

wlog("Opened $inputfile for reading");

}

while ($row = fgetcsv($inputfp, 1000, ",")){

$trimrow = trim($row, " ");

 

$count++;

writeLine($outfilefp, $trimrow);

}

if($count !== '0') {

wlog("finished the import with a total of $count records");

}else{

wlog("Failed to import data");

}

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.