Hi i have a little problem, i want to filter $array to get only music ! but when i run it , it displays everything in my folder include .jpg ,.. and . sorry if i'm not clear , English is not my native language. Thanks
$repertoire = "Classic";
$array = scandir($repertoire);
$arraymp3 = array();
foreach ($array as $element) {
if (strpos($element, '.mp3'));{
$arraymp3[] = $element;
}
}
$pieces = explode(".", $element);
$al = sizeof($pieces);
if ($pieces[$al-1] == ".mp3") {
$arraymp3[] = $element;
}
Try the above code instead =]
You will try like this
foreach ($array as $element) {
$ismp3String = strpos($element, '.mp3')
if ($ismp3String !== false){
$arraymp3[] = $element;
}
}
For more details you will read http://php.net/manual/en/function.strpos.php this carefully how it works
You can use the glob function.
$arraymp3 = glob("*.mp3");