Display all articles on sites from folders

I’m learning php and I decided to write a program to display all the site’s articles that are in folders, but I didn’t succeed… help or tell me what’s wrong.

<?php
for ($i = 1; $i <= 100; $i++) {
    $statji = "statji/$i";
    if (!file_exists($statji))
        break;
    $dir = opendir($statji);
    $raz = array(".html", ".htm", ".shtml", ".php");
    while (($file = readdir($dir)) !== false) {
        if(($file != ".") && ($file != "..") {
            if (in_array(strrchr($file, "."), $raz)) {
                $meta = get_meta_tags("$statji/$file");
                echo "<tr><td><a href='$statji/$file' target='_blank'>$meta[nazvanie]</a></td><td>$meta[avtor]</td></tr>";
            }
        }
    }
    closedir($dir);
}
$ind = basename($_SERVER['PHP_SELF'], ".php");
?>

Answer 1, authority 100%

Your problem is in the syntax… Let’s say:

$statji="statji/$i"; => $statji="statji/".$i;
$meta=get_meta_tags("$statji/$file"); => $meta=get_meta_tags($statji."/".$file);
echo "...target='_blank'>$meta[nazvanie]</a>..<td>$meta[avtor]</td>..";     
=>    
echo "...target='_blank'>".$meta[nazvanie]."</a>..<td>".$meta[avtor]."</td>..";

and so on. Read what the browser gives you (errors) and debug the script based on them.


Answer 2, authority 50%

error_reporting(E_ALL);
ini_set('display_errors', 1);

at the beginning of the script. And see the errors


Answer 3, authority 50%

You seem to have one mistake. The closing brace is missing in the if (($file != "..") && ...) { //code }conditional. Here is a working code, the only thing you will have to do is either rename the directory or correct it in the code to your standard.

<?php
for ($i = 1; $i <= 5; $i++) {
    $articles = 'articles/'.$i;
    if (!file_exists($articles)) {
        break;
    }
    $dir = opendir($articles);
    $ext = array(".html", ".htm");
    while (($file = readdir($dir)) != false) {
        if ($file == "." || $file == "..") {
            continue;
        }
        if (in_array(strrchr($file, "."), $ext)) {
            $meta = get_meta_tags($articles ."/". $file);
            //  ,  ,   
            // ,  - .
        }
    }
    closedir($dir);
}
?>