Creating a menu from array in PHP
I have got the following pulled from an array.
[TheBeautifulSouth/2-15 One Last Love Song.m4a] => Array
(
[name] => TheBeautifulSouth/2-15 One Last Love Song.m4a
[time] => 1296612503
[size] => 7628998
[hash] => 4c6d9b19310ad53efccc5df2e0632e82
)
[TheBeautifulSouth/2-16 Mirror.m4a] => Array
(
[name] => TheBeautifulSouth/2-16 Mirror.m4a
[time] => 1296612568
[size] => 8418448
[hash] => ef371e227b410bb4c9ed1ff7f2d0d70e
)
[TheBeautifulSouth/2-17 One God.m4a] => Array
(
[name] => TheBeautifulSouth/2-17 One God.m4a
[time] => 1296612639
[size] => 8619393
[hash] => 80f29fbef6f469e3f150f7011a320987
)
[TheBeautifulSouth/2-18 Blackbird On the Wire (Radio Ed.m4a] => Array
(
[name] => TheBeautifulSouth/2-18 Blackbird On the Wire (Radio Ed.m4a
[time] => 1296612712
[size] => 6776214
[hash] => fe13ced4b9fc26b013c241219c642095
)
[dnb/] => Array
(
[name] => Music/dnb/
[time] => 1296576896
[size] => 0
[h开发者_开发百科ash] => d41d8cd98f00b204e9800998ecf8427e
)
[dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3] => Array
(
[name] => dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3
[time] => 1296577218
[size] => 11782889
[hash] => 372e32ad1aff44061b65f5a76e7e805c
)
[Music/dnb/21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3] => Array
(
[name] => dnb/21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3
[time] => 1296577357
[size] => 8260946
[hash] => 7fda7e838192f5c362f71ffff300a8c3
)
[dnb/Abort_Delta Heavy_192.mp3] => Array
(
[name] => dnb/Abort_Delta Heavy_192.mp3
[time] => 1296577451
[size] => 8080602
[hash] => bb71d713fd77746cd7debb39407ba88f
)
here is the output.
TheBeautifulSouth/2-15 One Last Love Song.m4anum2
TheBeautifulSouth/2-16 Mirror.m4anum2
TheBeautifulSouth/2-17 One God.m4anum2
TheBeautifulSouth/2-18 Blackbird On the Wire (Radio Ed.m4anum2
dnb/03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3num2
dnb/21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3num2
dnb/Better Place_Dub Zero_192.mp3num2
dnb/Body_Shot_Tantrum_Desire_192.mp3num2
I am trying to put this into a menu structure as follows.
<ul>
<li>
<ul>
TheBeautifulSouth
<li>2-15 One Last Love Song.m4anum2</li>
<li>2-16 Mirror.m4anum2</li>
<li>2-17 One God.m4anum2</li>
<li>2-18 Blackbird On the Wire (Radio Ed.m4anum2</li>
</ul>
</li>
<li>
<ul>
dnb
<li>03 Twerk feat. Yo Majesty (Sub Focus Remix).mp3num2</li>
<li>21st Century (Feat. Cabbie)_Tantrum Desire_192.mp3num2</li>
<li>Better Place_Dub Zero_192.mp3num2</li>
<li>Body_Shot_Tantrum_Desire_192.mp3num2</li>
</ul>
</li>
I am trying to use the php function strstr but can't figure it out. Here is my code:
<ul>
<li>list
<ul>
<?php foreach ($bucket_contents as $file){
$fname = $file['name'];
$list = strstr($fname, '/', true); ?>
<li><?php echo $list; ?></li>
<?php } ?>
</ul>
</li>
</ul>
If your variables have the values they should have (try a var_dump
), the only problem I can see, is your php version. Are you sure your server is running php 5.3?
Note that the third parameter in strstr
is only available in php 5.3.
by using strstr($fname, '/', true);
you're actually telling php to return everything before the character "/". if you drop the "true", you'll receive everything from, including the "/" character.
you can do something like
$list = substr($fname, strpos($fname, "/") +1);
精彩评论