Advent of code 2017/19
Ajax Direct

Answer

Part 1 :
Part 2 :
$grid    = (array) $input->lines->map(fn ($line) => str_split($line));
[$x, $y] = [array_search("|", $grid[0]), 0];
$dir     = [0, 1];

$solution_1 = "";
$solution_2 = 0;

while (true) {
    $solution_2++;
    [$x, $y] = [$x + $dir[0], $y + $dir[1]];
    if (empty($grid[$y][$x]) || $grid[$y][$x] == " ") break;

    if (preg_match("/[A-Z]/", $grid[$y][$x])) {
        $solution_1 .= $grid[$y][$x];
    }

    if ($grid[$y][$x] == "+") {

        $dir = $dir[0]
            // Moving on X axis
            ? [0,  preg_match("/[A-Z|]/", ($grid[$y - 1][$x] ?? "")) ? -1 : 1]
            // Moving on Y axis
            : [preg_match("/[A-Z-]/", ($grid[$y][$x - 1] ?? "")) ? -1 : 1, 0];
    }
}