Page 1 of 1
file open, add mysql database for each section
Posted: Sun Dec 29, 2002 10:51 am
by phice
ok, so I've got a file with hundreds of little sections, much like the following:
File:3D_Ultra_Cool_POOL.EXE
Length:156005594 Bytes,152349KB
UUHash:=myTDhYcJg4v03KDQPl7fpOXidFI=
For File, I want that to go into a mysql database table, under column FILE. Length under LENGTH, UUHash under UUHASH. And all in one row. And each column would not include anything before the :, nor the :.
Any ideas on how to do such a thing? Need more information?
Posted: Sun Dec 29, 2002 8:00 pm
by Gen-ik
Are all of the sections devided by a blank line or a special character?
Is the file a .txt file?
Posted: Sun Dec 29, 2002 11:40 pm
by phice
Here's a portion of the
.txt file:
File:3D_Ultra_Cool_POOL.EXE
Length:156005594 Bytes,152349KB
UUHash:=myTDhYcJg4v03KDQPl7fpOXidFI=
File:AQUANOX.EXE
Length:185422848 Bytes,181077KB
UUHash:=pbGrzFVasD3jHKFvh1Zv5BI4c2Q=
File:BATTLE_REALMS.EXE
Length:151040742 Bytes,147501KB
UUHash:=3vGJRrsGtOMa2w89+HLXFPSv+5Q=
File:BLADE_OF_DARKNESS.EXE
Length:195208527 Bytes,190633KB
UUHash:=foI6DUrhotl1UWzihRkcIQoyB4Y=
File:C_C_RENEGADE.EXE
Length:187781360 Bytes,183380KB
UUHash:=2C38tOa+ygkZjeh+WENUD9QlVfc=
Each group is seperated by two \n.
Posted: Mon Dec 30, 2002 9:22 am
by Gen-ik
Okey.
Well.. as long as the only place you have \n\n is between each section then it should be pretty easy to do.. I think.
The first thing that I would do if I was trying to do the same thing would be to load the entire text file into a variable named $thefile.
Then once you have it use the explode() function to split that variable into chunks like this... $chunks=explode("\n\n",$thefile);
Now you will have an array called $chunks which contains each section.
From here you could do some like this..
Code: Select all
<?php
$number_of_chunks=count($chunks); //get the number of chunks
$loop=0;
while($loop<=$number_of_chunks)
{
$tinychunk=explode("\n",$chunks[$loop]);
$tinychunk[0]=str_replace("File:","",$tinychunk[0]);
$tinychunk[1]=str_replace("Length:","",$tinychunk[1]);
$tinychunk[2]=str_replace("UUHash:","",$tinychunk[2]);
mysql_query("INSERT INTO `your_table` (`file`,`length`,`uuhash`) VALUES ('$tinychunk[0]','$tinychunk[1]','$tinychunk[2]')";
$loop++;
}
?>
If everything works it should split up your file into bits and then add each bit into your database as you want.
You will obviously need to add your database connection code in their.. and you may need to tweek the code a bit but it should give you a rough idea of what to do.
Hope this helps.
Posted: Mon Dec 30, 2002 7:43 pm
by phice
Worked perfect.
