I have an array that loops through music tracks but I need to remove the comma from the last element of the array, can someone help?
<?php foreach ($bucket_contents as $file){ $fname = $file['name']; $furl = "http://".$isdHtml5Bucket.".s3.amazonaws.com/".urlencode($fname);
if(preg_match("/\.mp3$/i", $furl)) { ?>
{
name:"<?php echo basename($fname); ?>",
mp3:"<?php echo $furl; ?>"
},
<?php }else{ ?>
{
name:"<?php echo basename($fname); ?>",
m4a:"<?php echo $furl; ?>"
},<?php } } ?>
And here is the output of the array.
{
name:"bassline",
m4a:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fbassline%2F"
},
{
name:"Project Bassline - Drop The Pressure (Jack Beats Rinsed Out Remix).mp3",
mp3:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fbassline%2FProject+Bassline+-+Drop+The+Pressure+%28Jack+Beats+Rinsed+Out+Remix%29.mp3"
},
{
name:"deadmau5 vs jelo the reward is cheese.mp3",
mp3:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fdeadmau5+vs+jelo+++the+reward+is+cheese.mp3"
},
{
name:"vocal",
m4a:"http://suyssamuelarawaeast.s3.amazonaws.com/warehouse%2Fvocal%2F"
},
{
name:"Thin Ice",
free:true,
mp3:"http://www.jplayer.org/audio/mp3/Miaow-10-Thin-ice.mp3",
oga:"http://www.jplayer.org/audio/ogg/Miaow-10-Thin-ice.ogg"
},
If you scroll to the last element of the array you can see a comma is output.
I really need to remove this comma from the last element of the array.
Thanks
pass your string through
rtrim()and specify the comma in the charlist as a removable character:Edit
Or… perhaps this approach (not tested):