Closed Thread Icon

Topic awaiting preservation: Acssessing data in a file (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13123" title="Pages that link to Topic awaiting preservation: Acssessing data in a file (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Acssessing data in a file <span class="small">(Page 1 of 1)</span>\

 
Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 04-05-2004 18:12

Hey Im makeing a script that uses data already established via another script thats coded in perl/cgi, Im prgoramming my script in PHP
anyway I need to extract the following fields from the file

  • AccountCreated

  • LastLogin

  • WaitAdminApprove

  • email_address

  • AuthorUserFolder

  • Username

  • FullName



From a text file which is named $username.txt an example of a data file is

quote:
AccountCreated=1046368823=
Author%3AUserFolder=%2Fhome%2Fthebronze%2F=
Author%3AUserURL=http%3A%2F%2Fwww.the-bronze.me.uk%2F=
Cols=90=
DiskUse=1=
FontSize=10=
LastLogin=1066385750=
LastLoginFrom=81.108.97.42=
Quota=10000=
Rows=20=
ShowDirSize=1=
ShowFolderTop=1=
ShowMFCTip=1=
ShowTips=1=
Sort=t=
TextUpload=1=
TextWrap=0=
Username=superfly=
WaitAdminApprove=0=
_BUILD=33=
_VERSION=2.1.0.0033=
account_expires_days=30=
account_status=0=
allow_cgi=1=
allow_folder_change=1=
allow_no_quota=1=
email_address=no_matter%40hotmail.com=
full_name=Ben=
language=english=
listings_per_page=100=
min_pages_for_select_option=8=
multi_upload_count=50=
p_hidden=0=
p_upload=2=
priv_scheme=0=
shell=2=
show_chdir=1=
sort_insensitive=0=
text_eoln=0=
text_exts=js%20pl%20cgi%20sh%20php%20php3%20js%20txt%20htm%20html%20css%20doc%20xls%20pps%20mdb%20swf=
time_display=2=
use_chdir=1=
use_he_copy=1=
use_he_delfile=1=
use_he_delfolder=1=
use_he_edit=1=
use_he_mkdir=1=
use_he_mkfile=1=
use_he_rename=1=
use_he_ri=1=
use_he_show=1=
use_he_val=1=
use_html_editor=1=
use_htpasswd=1=
use_my_account_page=1=
use_template_editor=1=
use_templates==



I do very little work with PHP or file manipulation most of the work I do is with mysql and other database software,
how can I grab the relative fields into 'userable' variables? Is my best bet running the filename threw the file(); using a str_* function to check for my chosen fields and then exploding at the = ?

or is there a more elegant solution?

Thanks In advance
Trigger



[This message has been edited by Trigger (edited 04-05-2004).]

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-05-2004 18:23

parse_ini_file

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 04-05-2004 18:34

That Dosent work because it's not setup like a typical ini file,
It will parse the first line but then it chokes
giving me a Warning
I figure its due to the end = on the line , any other ideas?


Thanks Again
Trigger

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-05-2004 18:35

actually, since them are url encoded, parse_str might be a better option. After replacing \n with & at least.

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 04-05-2004 18:37

TP thanks for your help but you've lost me,
are you suggesting that I do file($file)
do a sub_str for /n and &
and then parse_str?

Thanks
Trigger

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-05-2004 18:58

well, if you do file($strFilename),
you'll need to loop over each and use parse_str.
What I was suggesting was you do

code:
if ($fh = fopen($strFilename))
{
$strData = fread($fh,filesize($strFilename));
fclose($fh);
$strData = str_replace(array("=\r\n","=\n\r","=\n")'&,$strData);
$arrFileContents = parse_str($strData);
if ($arrFileContents['AccountCreated'] == '1046368823')
print 'success';
else
print 'something still wrong';
}



Edit: Feel free to drop into icq , if you need further, faster, help.

[This message has been edited by Tyberius Prime (edited 04-05-2004).]

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 04-05-2004 19:05

Thanks for that TP, I'll give it a go and have a play around

Thanks
Trigger

« BackwardsOnwards »

Show Forum Drop Down Menu