Advent of code 2017/9
Ajax Direct

Answer

Part 1 :
Part 2 :
// Remove cancelled characters
$input = preg_replace("/\!./", "", $input);

// Remove garbage
$input = preg_replace_callback("/<(.*?)>/", fn ($a) =>
    str_repeat("#", strlen($a[1]))
, $input);

// Count groups
$groups = 0;
$score  = 0;

for ($i = 0; $i < strlen($input); $i++) {
    if ($input[$i] == "{") {
        $groups++;
        $score += $groups;
    } elseif ($input[$i] == "}") {
        $groups--;
    }
}

// ==================================================
// > SOLUTIONS
// ==================================================
$solution_1 = $score;
$solution_2 = substr_count($input, "#");