-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_css.php
More file actions
43 lines (36 loc) · 1.06 KB
/
Copy pathvalidate_css.php
File metadata and controls
43 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
$css = file_get_contents('./scrollytelling/styles.css');
$errors = [];
// Simple CSS validation - check for common issues
$lines = explode(PHP_EOL, $css);
$braceCount = 0;
$inComment = false;
$lineNum = 1;
foreach ($lines as $line) {
$line = trim($line);
// Track multi-line comments
if (strpos($line, '/*') !== false) $inComment = true;
if (strpos($line, '*/') !== false) $inComment = false;
if (!$inComment && !empty($line)) {
$braceCount += substr_count($line, '{');
$braceCount -= substr_count($line, '}');
// Check for unmatched braces
if ($braceCount < 0) {
$errors[] = "Line $lineNum: Extra closing brace '}'";
}
}
$lineNum++;
}
if ($braceCount !== 0) {
$errors[] = "Unmatched braces - final count: $braceCount";
}
if (empty($errors)) {
echo "✓ CSS file is VALID - No syntax errors detected.\n";
echo "✓ Brace count is balanced (0)\n";
} else {
echo "✗ CSS file has ERRORS:\n";
foreach ($errors as $err) {
echo " - $err\n";
}
}
?>