Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to: insert space char or tab char to a file

Status
Not open for further replies.

zyrag

IS-IT--Management
Dec 4, 2002
252
PH
i tried using fwrite($outfile,"\040) to insert a 'space' char and fwrite($outfile,"\t") for a 'tab' char but they don't seem to work. how then do i insert a 'space' or a 'tab' character to a file?

thanks,
 
correction: fwrite($outfile,"\040") where $outfile is obtained through $outfile=fopen("outfile.txt","a+")
 
but they don't seem to work
How are you testing this? Viewing it through a browser or in a program like notepad?

//Daniel
 
for danielhozac, testing is done by executing the php script through the brwoser, then issue at the shell: #more outfile.txt.

for sleipner, i tried it too but didn't work either. did it work with yours?


 
And you succeed in opening the file (no error messages regarding permissions, for instance)?

//Daniel
 
permission looks ok, i can open (read/write) it without errors.

i'm thinking by now of other alogorithm. i'm thinking of using the file function to read the content of the $infile then do the manipulation with the result array and then save changes to the $outfile. what do you think?

has anyone here created some sort of utility for converting csv file to fixed-width format?

hope you could share your thoughts, algorithm, whatever that might help me with this....

 
zyrag:
printing a space works for me.


I generally recommend against reading an entire file into memory if you are going to manipulate it row-by-row. A sufficiently large input file could cause your code to exceed resource limits.

I would read in the CSV line by line, split it at whatever the field terminator is, then use concatentation and substrings to output fixed-width data to the output file.

Want the best answers? Ask the best questions: TANSTAAFL!
 
thanks sleipnir, your ideas are valuable to me...

i'll try working it with your advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top