Simple PHP question - (Solving problems makes you feel good)
Moderator: General Moderators
Simple PHP question - (Solving problems makes you feel good)
--
I am creating a menu in Flash MX.
From Flash, I desperately need to retrieve the contents of a folder in my root directory (MC1), strip the dot extensions (.swf) and create an Array out of the modified file names.
So when I access the .PHP script from flash, it will look at ...
Folder-MC1
item1.swf
item2.swf
item3.swf
item4.swf
item5.swf
and return ...
z = new Array("item1", "item2", "item3", "item4", "item5");
This is my first post here!
I did search this site for about an hour with no success (doesn’t mean its not here).
Any help would be greatly appreciated.
Thank you in advance,
Mike
--
I am creating a menu in Flash MX.
From Flash, I desperately need to retrieve the contents of a folder in my root directory (MC1), strip the dot extensions (.swf) and create an Array out of the modified file names.
So when I access the .PHP script from flash, it will look at ...
Folder-MC1
item1.swf
item2.swf
item3.swf
item4.swf
item5.swf
and return ...
z = new Array("item1", "item2", "item3", "item4", "item5");
This is my first post here!
I did search this site for about an hour with no success (doesn’t mean its not here).
Any help would be greatly appreciated.
Thank you in advance,
Mike
--
--
Did I mention I don’t know anything about PHP?
That looks simple enough… What do I do with it?
Let’s see…
$myArray = explode(".",$myListVar);
“.” – is this retrieving the file name up to the dot extension (item-.swf)?
$myListVar – doesn’t this need to be defined before I can explode() it?
$myArray – do I change this to “$z” if I want my new Array to be “z”?
I’m just not sure how this …
$myArray = explode(".",$myListVar);
will return this …
z = new Array("item1", "item2", "item3", "item4", "item5");
--
Did I mention I don’t know anything about PHP?
That looks simple enough… What do I do with it?
Let’s see…
$myArray = explode(".",$myListVar);
“.” – is this retrieving the file name up to the dot extension (item-.swf)?
$myListVar – doesn’t this need to be defined before I can explode() it?
$myArray – do I change this to “$z” if I want my new Array to be “z”?
I’m just not sure how this …
$myArray = explode(".",$myListVar);
will return this …
z = new Array("item1", "item2", "item3", "item4", "item5");
--
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
You could try
Code: Select all
$z = array();
foreach (glob("MC1 /*.swf") as $filename) {
$newvar = explode('.',$filename);
$z[] = $newvar[0];
}--
This looks like it could work (what do I know?).
Let’s see . . .
$z = array();
foreach (glob("MC1 /*.swf") as $filename) {
$newvar = explode('.',$filename);
$z[] = $newvar[0];
}
glob("MC1 /*.swf") – is there supposed to be a space between “MC1” and “/”?
explode('.',$filename); – I’m still not sure what this - ‘.’ is doing.
$z[] = $newvar[0]; – wont this return the first item in the Array (z = item1)?
We are getting closer. I can feel it.
--
This looks like it could work (what do I know?).
Let’s see . . .
$z = array();
foreach (glob("MC1 /*.swf") as $filename) {
$newvar = explode('.',$filename);
$z[] = $newvar[0];
}
glob("MC1 /*.swf") – is there supposed to be a space between “MC1” and “/”?
explode('.',$filename); – I’m still not sure what this - ‘.’ is doing.
$z[] = $newvar[0]; – wont this return the first item in the Array (z = item1)?
We are getting closer. I can feel it.
--
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
the space between MC1 and / doesnt matter, it is read the same (i think)gullineglob wrote:("MC1 /*.swf") – is there supposed to be a space between “MC1” and “/”?
explode('.',$filename); – I’m still not sure what this - ‘.’ is doing.
$z[] = $newvar[0]; – wont this return the first item in the Array (z = item1)?
We are getting closer. I can feel it.
--
explode turns the $filename into a array by the "." so if the $filename = this.is.a.sentence then the array will look like this
Code: Select all
array('this', 'is', 'a', 'sentence');how close are we now?
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
I suggest you read this: viewtopic.php?t=21400
--
Just a little more help.
So, this code,
returns the word “Array” for every “.swf” file in my MC1 folder
like this . . .
ArrayArrayArrayArrayArrayArrayArrayArray
What I need is . . .
“Item1”, “Item2”, “Item3”, “Item4”, “Item5”, “Item6”, “Item7”
Any ideas?
Mike
--
Just a little more help.
So, this code,
Code: Select all
<?PHP
$z = array();
foreach (glob("e;MC1/*.swf"e;) as $filename) {
$newvar = explode('.',$filename);
$zї] = $newvarї0];
echo $z;
}
?>like this . . .
ArrayArrayArrayArrayArrayArrayArrayArray
What I need is . . .
“Item1”, “Item2”, “Item3”, “Item4”, “Item5”, “Item6”, “Item7”
Any ideas?
Mike
--
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
This is building an array, as you wanted.gulline wrote:...and create an Array out of the modified file names.
Code: Select all
$z = array();
foreach (glob("e;MC1 /*.swf"e;) as $filename) {
$newvar = explode('.',$filename);
$zї] = $newvarї0];
}Code: Select all
$z = array();
foreach (glob("MC1 /*.swf") as $filename) {
$newvar = explode('.',$filename);
echo $newvar[0];
}YES!
that wasn't my problem but it totaly helped
echo $z; <--- i should have been using echo $z[0];
Thanks.
Mike
that wasn't my problem but it totaly helped
Code: Select all
<?PHP$z = array();
foreach (glob("e;MC1/*.swf"e;) as $filename) {
$newvar = explode('.',$filename);
$zї] = $newvarї0];
echo $z; <--- i should have been using echo $zї0];
}
?>Thanks.
Mike
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
--
I have this menu in flash.
http://www.mikegulline.com/z/z.html
MC2, MC3, MC4 are all pulling from these Arrays in Flash;
-- MC2.z = new Array("item1", "item2", "item3","item4");
-- MC3.z = new Array("item1", "item2", "item3","item4", "item5", "item6", "item7", "item8", "item9", "item10");
-- MC4.z = new Array("item1", "item2");
I need to define “MC1.z[]” in Flash using PHP.
The code does the right thing; it just doesn’t seem to be formatted the right way
from this php code i get -- item1/item2/item3/item4/item5
i need to have ----------- "item1", "item2", "item3","item4", "item5"
is that the same thing?
I don’t think I am calling it correctly in flash. Should I be finishing my question in a flash forum? i trust the php, it's the flash im not sure about. FLASH!
Bah!
--
I have this menu in flash.
http://www.mikegulline.com/z/z.html
MC2, MC3, MC4 are all pulling from these Arrays in Flash;
-- MC2.z = new Array("item1", "item2", "item3","item4");
-- MC3.z = new Array("item1", "item2", "item3","item4", "item5", "item6", "item7", "item8", "item9", "item10");
-- MC4.z = new Array("item1", "item2");
I need to define “MC1.z[]” in Flash using PHP.
The code does the right thing; it just doesn’t seem to be formatted the right way
from this php code i get -- item1/item2/item3/item4/item5
i need to have ----------- "item1", "item2", "item3","item4", "item5"
is that the same thing?
I don’t think I am calling it correctly in flash. Should I be finishing my question in a flash forum? i trust the php, it's the flash im not sure about. FLASH!
Bah!
--