<?php
$files = ['charity_members.php', 'charity_plans.php', 'committees.php', 'expenses.php', 'accounts.php', 'accounting.php'];
foreach ($files as $file) {
    if (file_exists($file)) {
        $content = file_get_contents($file);
        
        // Use ~ as delimiter to avoid issues with /
        $pattern1 = "~htmlspecialchars\(\s*\\\$([a-zA-Z0-9_]+)\\[\'([a-zA-Z0-9_]+)\\'\]\s*\)~s";
        $pattern2 = '~htmlspecialchars\(\s*\$([a-zA-Z0-9_]+)\["([a-zA-Z0-9_]+)"\]\s*\)~s';
        
        $content = preg_replace($pattern1, "htmlspecialchars(\\\\$1[\\\'\\2\\] ?? '')", $content);
        $content = preg_replace($pattern2, 'htmlspecialchars($\1["\2"] ?? "")', $content);
        
        file_put_contents($file, $content);
        echo "Processed $file\n";
    }
}
?>