<?php
// Find the closing brace for the if ($_SERVER['REQUEST_METHOD'] == 'POST') statement
$content = file_get_contents('students/add.php');
$lines = explode("\n", $content);

$brace_count = 0;
$start_line = -1;

// Find the if statement
for ($i = 0; $i < count($lines); $i++) {
    if (strpos($lines[$i], "if (\$_SERVER['REQUEST_METHOD'] == 'POST')") !== false) {
        $start_line = $i;
        echo "Found POST if statement at line " . ($i + 1) . "\n";
        break;
    }
}

if ($start_line != -1) {
    // Count braces from this point
    for ($i = $start_line; $i < count($lines); $i++) {
        $line = $lines[$i];
        $brace_count += substr_count($line, '{');
        $brace_count -= substr_count($line, '}');
        
        if ($brace_count == 0) {
            echo "Matching closing brace found at line " . ($i + 1) . "\n";
            echo "Line content: " . $lines[$i] . "\n";
            break;
        }
    }
    
    if ($brace_count != 0) {
        echo "ERROR: Unclosed brace found!\n";
    }
} else {
    echo "Could not find POST if statement\n";
}
?>