Page 1 of 1

Simple PHP question - (Solving problems makes you feel good)

Posted: Thu May 26, 2005 2:56 pm
by gulline
--

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

--

Posted: Thu May 26, 2005 3:03 pm
by Burrito
explode()

ex:

Code: Select all

$myArray = explode(".",$myListVar);

Posted: Thu May 26, 2005 3:48 pm
by gulline
--

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");

--

Posted: Thu May 26, 2005 3:51 pm
by John Cartwright
You could try

Code: Select all

$z = array();
foreach (glob("MC1 /*.swf") as $filename) {
   $newvar = explode('.',$filename);
   $z[] = $newvar[0];
}

Posted: Thu May 26, 2005 5:52 pm
by gulline
--

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.

--

Posted: Thu May 26, 2005 5:58 pm
by shiznatix
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.

--
the space between MC1 and / doesnt matter, it is read the same (i think)
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');
$newvar[0] would = 'this' since its the first element in the array (and is given the key '0' because the count starts with 0)

how close are we now?

Posted: Thu May 26, 2005 8:45 pm
by gulline
--

We’re this close (I’m doing this with my fingers).
One last bone head question. It’s a two parter.

Can I test something like this on my local computer? Does it have to be on a server for some reason?

--

Posted: Thu May 26, 2005 8:55 pm
by Ambush Commander
I suggest you read this: viewtopic.php?t=21400

Posted: Sat May 28, 2005 11:50 am
by gulline
--

Just a little more help.

So, this code,

Code: Select all

<?PHP
$z = array();
foreach (glob(&quote;MC1/*.swf&quote;) as $filename) {
   $newvar = explode('.',$filename);
   $z&#1111;] = $newvar&#1111;0];
   echo $z;
}
?>
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

--

Posted: Sat May 28, 2005 11:55 am
by John Cartwright
gulline wrote:...and create an Array out of the modified file names.
This is building an array, as you wanted.

Code: Select all

$z = array();
foreach (glob(&quote;MC1 /*.swf&quote;) as $filename) {
   $newvar = explode('.',$filename);
   $z&#1111;] = $newvar&#1111;0];
}
If you want to directly output your contents

Code: Select all

$z = array();
foreach (glob("MC1 /*.swf") as $filename) {
   $newvar = explode('.',$filename);
   echo $newvar[0];
}

Posted: Sat May 28, 2005 12:16 pm
by gulline
YES!

that wasn't my problem but it totaly helped

Code: Select all

<?PHP$z = array();
foreach (glob(&quote;MC1/*.swf&quote;) as $filename) {   
$newvar = explode('.',$filename);   
$z&#1111;] = $newvar&#1111;0];   
echo $z; <--- i should have been using echo $z&#1111;0];
}
?>
echo $z; <--- i should have been using echo $z[0];

Thanks.

Mike

Posted: Sat May 28, 2005 12:33 pm
by John Cartwright
No $z[0] is only the first array element.
You need to echo $newvar[0] for what you want.

Good luck.

Posted: Sat May 28, 2005 12:56 pm
by Burrito
once you have the z[] array built, you'll need to loop over it to display the values from its elements.

DO THAT OUTSIDE OF YOUR CURRENT FOREACH LOOP OTHERWISE IT WILL BE COMPOUNDED.

Posted: Mon May 30, 2005 2:04 pm
by gulline
--

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!
--