LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-04-2006, 01:06 AM   #1
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 837

Rep: Reputation: 35
Storing numbers as 4 bytes in PHP.


How can I write time stamps to file in 4 byte format in PHP?
Is it necessary to play with chr()?

I have strings containing a number of time stamps, the ASCII representation of the numbers takes many times the 4 bytes originally required to store the value and I want to save disk space.

If the solution is complicated I can write the script in assembly (don't know C).

Thank you for your help.
 
Old 02-04-2006, 01:59 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Try looking here:

http://www.felixgers.de/teaching/php/fileIO.html

You might be able to:

1. Open your file in "binary" mode

2. Use the string "pack()" and "unpack()" functions to copy the binary data
into/out of your PHP file I/O functions.

3. Use "$s = fread (int fp, int length)" and "fwrite (int fp, string $s, int length)" to do the actual I/O.

Just a thought .. PSM
 
Old 02-04-2006, 03:03 AM   #3
airswit
Member
 
Registered: Dec 2005
Distribution: Fedora 4
Posts: 89

Rep: Reputation: 15
can't you use the time() function? that returns an integer, which is smaller than the string. seems like it is exactly what you are looking for, and best thing: its built in!
 
Old 02-04-2006, 09:54 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by airswit
can't you use the time() function? that returns an integer, which is smaller than the string. seems like it is exactly what you are looking for, and best thing: its built in!
Looks like the right one to me! Although if the value is already in a string format then strtotime() should be able to come to the rescue
 
Old 02-04-2006, 11:06 PM   #5
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 837

Original Poster
Rep: Reputation: 35
Thank you for your solutions, the link is a great tutorial I was unaware of.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TX bytes vs. httpd bytes ovrload Linux - Networking 3 10-12-2005 05:19 PM
Password storing program? Ariod Linux - Software 2 09-09-2005 07:25 PM
Storing Strings ToothlessRebel Programming 4 09-05-2004 04:16 AM
Adding numbers, break on non-numbers... Cruger Programming 1 03-22-2004 10:18 AM
Storing /home in CVS Cyth Linux - General 2 01-03-2003 04:10 AM


All times are GMT -5. The time now is 10:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration