Page 1 of 1
Need help getting string variables into array
Posted: Tue Feb 08, 2005 8:31 pm
by Summerschool23
Hello, I am working on a project involving php reading external files and I am having trouble figuring out a way to get variables in the external file into an array. The external file variables are like
Code: Select all
#var1:var1 text;
#var2:var2 text;
#var3:var3 text;
and I need to put just the values of the variables into an array looking like this (there are multiple files)
Code: Select all
&array=|var1 text,var2 text,var3 text|var1 text,var2 text,var3 text
any ideas...
Posted: Tue Feb 08, 2005 9:04 pm
by feyd
Your examples don't seem to correlate into a conversion logically.
you will need to create a parser for the external files. Depending on the flexibility you need, it may involve explode() and strpos() or regular expressions. It's possible you may use file() to break apart the file into seperate lines.. but that all depends on the language you create or have been dictated.
This smells like a school project.

Posted: Wed Feb 09, 2005 4:14 pm
by Summerschool23
I can get the file into a string using get_file_contents, but I don't know what to do from there. Maybe I'll try one of those functions, but I already have been looking through the php manual a lot and haven't had much luck.
This isn't actually for school, just a hobby project. I'm creating a flash game and this is part of it.
Posted: Wed Feb 09, 2005 4:22 pm
by feyd
could you detail how the "language" works? This needs to be hard specifics.. once you have that, you can start down the path of creating a parser.
Posted: Wed Feb 09, 2005 4:32 pm
by Summerschool23
you mean the "language" as in the external file? That is just a widely used format for the game I am attepting to make. there are only about 5-15 variables, depending on what the author of the file wants in it. SOme variables are like
Code: Select all
#title:my title;
#creator:my username;
IDK if this is what you mean by the "language".
Posted: Wed Feb 09, 2005 5:19 pm
by feyd
is there a specification for this file format somewhere? Knowing how the files are laid out, we can better direct you to creating a parser.. or finding an existing one.
Which game?
Posted: Wed Feb 09, 2005 6:21 pm
by Summerschool23