Jump to content

Comma after line beside last one


Duerdum9

Recommended Posts

First of, this is my script:

<?php

$newline = "\n";
$directory='music/';
$extensions = array('mp3', 'ogg');

$filesArray = array();
$dir_handle = @opendir($directory) or die("There is an error with your file directory!");

while ($file = readdir($dir_handle)) 
{
    $filePath = $directory.$file;
    $info = pathinfo($filePath);
    if(in_array(strtolower($info['extension']), $extensions))
    {
        $filesArray[$info['filename']][$info['extension']] = $filePath;
    }
}

//sort($files_array, SORT_STRING);

$path_parts = pathinfo('musicogg');
foreach ($filesArray as $fileName => $files)
{
    if(count($files)==2)
    {
echo '{';
  echo  'mp3:"'.$files["mp3"].'",ogg:"'.$files["ogg"].'';
echo '},';
echo $newline;
    }
}
?>

Okay, so what I need, is the file to type a comma after each line beside the very last one. Currently it does it with everyone, but that's giving errors, so any ideas? Really appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/268039-comma-after-line-beside-last-one/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.