建议文本文件中的数据存储格式 [英] Suggestion needed on data storage format in text file

查看:73
本文介绍了建议文本文件中的数据存储格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发的项目不涉及数据库。我想解析邮箱文件(.mbx)的
并将摘要存储在文本文件中,以便快速检索和显示收件箱页面中的信息。


sugegsted格式如下:


#1


ID [4 bytes]:主题[100字节]:地址[100字节]:从

地址[100字节] ......等...


#2


而不是将固定大小预先设置为变量(因为实际数据可能更少或者可以增长到更多),我们可以连续存储值,

由一些独特的分隔符分隔(#|#,*#*,...)

1324#| #Hi,你好@@ google。 com#||@google.com#|# ...等

on

其中哪一个是有效的(因为会有频繁的)

插入/删除/更新个人信息,例如设置消息为

读取...,删除消息...,新消息...)


另外请建议如何确定变量siz e(100字节为#1中的
),并相应地为变量指定大小并在需要时读取它b / b
(区分多个变量)。


谢谢。


Manish

解决方案

Manish写道:


我正在开发的项目不涉及数据库。我想解析邮箱文件(.mbx)的
并将摘要存储在文本文件中,以便快速检索和显示收件箱页面中的信息。


sugegsted格式如下:


#1


ID [4 bytes]:主题[100字节]:地址[100字节]:从

地址[100字节] ......等...


#2


而不是将固定大小预先设置为变量(因为实际数据可能更少或者可以增长到更多),我们可以连续存储值,

由一些独特的分隔符分隔(#|#,*#*,...)

1324#| #Hi,你好@@ google。 com#||@google.com#|# ...等

on


其中哪一个是效果好的(如会有频繁的

插入/删除/更新个人信息,例如设置消息为

读取...,删除消息...,新消息.. 。)


另外请建议如何确定可变大小(#1中100字节为
),并相应地为变量指定大小并在需要时读取它b / b $(区分多个变量)。


谢谢。


Manish



就个人而言,我会使用数据库。我甚至不会尝试使用平面文件

。太多的工作试图保持正确。


但你问的是格式。只要数据量少于保留的金额,固定长度字段就会有额外空间。
保留。然后你会遇到一个问题,就是他的主题行超过了100个字符。并且4

字节允许最多9999个ID。够了吗?或者你打算尝试使用
来读/写二进制文件(在PHP中不容易)?


第二个是有问题的,因为用户可能包含你的

分隔符在其主题:行(如果你选择

错误的字符,甚至名称/地址)。


另外两种方式 - 使用CSV格式,PHP和其他程序提供了很好的文档和支持

。或者,在每个字段的开头添加一个长度字段,指定以下字段中的字符数。


但我仍然使用数据库。

-

==================

删除 X"来自我的电子邮件地址

Jerry Stuckle

JDS计算机培训公司
js ******* @ attglobal.net

==================


On Tue,2006年7月18日21:28:13 -0700,Manish写道:


#1

ID [4字节]:主题[100字节]:地址[100字节]:来自地址[100

字节] ......等等......


#2

1324#| #Hi,你怎么样@ google.com#||@google.com# |# ...


其中哪一个将是效果之一(因为会经常插入/删除/更新个别信息,例如设置消息) as

读取...,删除消息...,新消息......)



第一个将更高效从搜索/替换的角度来看,

从空间使用的角度来看,第二个会更有效率。

效率是主观的。

另外请建议如何确定变量大小(#1中100字节为
),并相应地为变量分配大小并读取它

(区分多个变量)在需要时。



substr将用于剪切字符串的各个部分(例如,从位置4开始的100

字符)和sprintf(或fprintf)在PHP5中完成它
如果你使用PHP5来保存步骤,则需要



如果你需要的不仅仅是指向正确函数的指针,然后它开始

听起来像是家庭作业,我希望你好运...


干杯,

Andy

-

Andy Jeffries MBCS CITP ZCE | gPHPEdit首席开发人员
http://www.gphpedit.org | Gnome 2的PHP编辑器
http://www.andyjeffries.co.uk |个人网站和照片


不要重新开车!

使用数据库,或者,如果你必须保持文档化的格式,如CSV或XML。


Ron:很酷:



The project I am developing doesn''t involves database. I want to parse
the mailbox file (.mbx) and store the summary in the text file for fast
retrieval and display of information in the Inbox page.

The sugegsted format are as:

#1

ID [4 bytes]: Subject [100 bytes]: To Address[100 bytes]: From
Address[100 bytes]...etc...

#2

Instead of preassining fixed size to variable (as actual data may be
much less or can grew to more), we can store the values continuously,
seperated by some unique seperator (#|#, *#*, ...)

1324#|#Hi, How are yo******@google.com#|****@google.com#|# ... and so
on
Which of these will be the efficeint one (as there will be frequent
insert/delete/update of the individual information, eg. set message as
read ..., delete message ..., new message ...)

Also please suggest on how to determine the variable size (100 bytes as
in #1), and assign the size to the variable accordingly and read it
(differentiate multiple variables) when required.

Thanks.

Manish

解决方案

Manish wrote:

The project I am developing doesn''t involves database. I want to parse
the mailbox file (.mbx) and store the summary in the text file for fast
retrieval and display of information in the Inbox page.

The sugegsted format are as:

#1

ID [4 bytes]: Subject [100 bytes]: To Address[100 bytes]: From
Address[100 bytes]...etc...

#2

Instead of preassining fixed size to variable (as actual data may be
much less or can grew to more), we can store the values continuously,
seperated by some unique seperator (#|#, *#*, ...)

1324#|#Hi, How are yo******@google.com#|****@google.com#|# ... and so
on
Which of these will be the efficeint one (as there will be frequent
insert/delete/update of the individual information, eg. set message as
read ..., delete message ..., new message ...)

Also please suggest on how to determine the variable size (100 bytes as
in #1), and assign the size to the variable accordingly and read it
(differentiate multiple variables) when required.

Thanks.

Manish

Personally, I''d use a database. I wouldn''t even try a flat file for
this. Too much work trying to keep things straight.

But you asked about the formats. The fixed length fields will have
extra space any time the amount of data is less than that of the amount
reserved. Then you run into the problem of someone who gets very
verbose with their subject line and exceeds the 100 characters. And 4
bytes allows up to 9999 ID''s. Is that enough? Or are you going to try
to read/write binary (not easy in PHP)?

The second one is problematical because the user may include your
separator in its Subject: line (or even name/address if you pick the
wrong character).

Two other ways - use CSV format, which is well documented and supported
by PHP and other programs. Or, add a length field at the beginning of
each field, specifying how many characters in the following field.

But I''d still use a database.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


On Tue, 18 Jul 2006 21:28:13 -0700, Manish wrote:

#1
ID [4 bytes]: Subject [100 bytes]: To Address[100 bytes]: From Address[100
bytes]...etc...

#2
1324#|#Hi, How are yo******@google.com#|****@google.com#|# ... and so on
Which of these will be the efficeint one (as there will be frequent
insert/delete/update of the individual information, eg. set message as
read ..., delete message ..., new message ...)

The first one will be more efficient from a search/replace point of view,
the second will be more efficient from a space usage point of view.
Efficiency is subjective.

Also please suggest on how to determine the variable size (100 bytes as
in #1), and assign the size to the variable accordingly and read it
(differentiate multiple variables) when required.

substr would be used to cut out various portions of the string (e.g. 100
charactes starting at position 4) and sprintf (or fprintf to do it in PHP5
if you''re using PHP5 to save a step).

If you need more than a pointer to the right functions, then it''s starting
to sound like a homework assignment and I wish you luck with it...

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos


Don''t re-ivent the wheel!
Either use a data base or, if you must, stay with well documented formats like CSV or XML.

Ron :cool:


这篇关于建议文本文件中的数据存储格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆