This is for
http://210.11.113.96/modweb/unit.php?unit=armcom, yes.
PauloMorfeo wrote:Maelstrom wrote:... I have no idea how to do it in php so that it can parse ~500 files in under 30 seconds. ...
You don't. You parse the files with some program, like vb, taking as long as you want, and fill a database. Then the php accesses the database.
Not everyone has the ability to run programs on their webserver, as most people rent space from a web host. So im making this all in PHP so everyone can use it. Plus you can run it on linux, unlike VB programs.
PauloMorfeo wrote:Where you're saying you're filling a database. If you have the databse filled, why would you want to be accessing the mod's structure directly from the files with php?
The way this thing will work is like this:
Dump all the FBI files into a FBI folder.
Run the LoadUnits.php script, which opens up the FBI files and dumps them in the database.
Grab the data from the database as needed, which you can see happening in that link i posted at the top.
PauloMorfeo wrote:Anyway, that's interesting. How is the structure of that database you're using?
I can upload the one i'm using for my program (the most recent version).
The way im doing it is in no way the most efficient way of doing it. But, with my somewhat limited PHP/MySQL skills (im still learning half the stuff as I go), the only way I could conceviably do it. The structure is like this:
Code: Select all
Unit Table:
id - Not used for anyhting, just the key
unitname - The unitname of the unit. ARMCOM for the commander, ect. Read from the FBI files
stat - the name of the property. 'description' for 'description=Commander'
value - the value of the property. 'Commander' for 'description=Commander'
When filled out, the unit table will look a little like this:
Code: Select all
| id | unitname | stat | value |
+------+----------+------------+---------+
| 1 | ARMCOM | name | Commander |
| 2 | ARMCOM | unitname | ARMCOM |
| 3 | ARMCOM | metalcost | 12345 |
| 4 | ARMCOM | energycost | 234567 |
| 5 | CORCOM | name | Commander |
| 6 | CORCOM | untiname | CORCOM |
Again, this would not be the most efficient way to do things. But short of altering the table's layout by adding a new column for every new tag, this is the only way I could think of doing it. And I dont really want to alter the table, as that could just get confusing.
If your database is better than this, please send it over, as I would be happy to improve my design.
Also, ive been thinking of a way of loading in alot of files, and I think ive come up with a good way of doing it.
Code: Select all
function ParseFile($fileString)
{
$file = array();
//Loop through each character in the file
for ($i++ while $i < strlen($fileString))
{
$chr = character $i in $fileString;
switch ($chr)
{
//Begining of a [section]
case "[":
$sectionName = string between $i and the next "]";
$newFileString = string between $i and the closing '}';
$file[$sectionName] = ParseFile($newFileString);
$i = position of the closing "}"
//Its a setting.
default:
$setting = string betweem $i and the next ";";
$file[bit before the "="] = bit after the "=";
$i = position of the ";"l
}
}
}
The above code, when its working, would output something like this:
Code: Select all
$file = Array
(
Setting1 = Value;
Setting2 = Value;
Section = Array
(
Setting3 = Value;
Setting4 = Value;
)
)
With as many nested arrays as the file has. You would access the values like so:
$file['SectionName']['SubSection']['Setting'] = 'Value';
Again, this probably isnt the best way of doing things, but its all I can come up with. Any input is welcome.