Show parent categories of the current category

Another way to go about it instead of substring, would be to use implode/explode & array filter.

echo implode(" » ", array_filter( explode(" » ", get_category_parents( $cat, true, " » ") ) ) );

Breaking that down:

Start with your original string.

$string = get_category_parents( $cat, true, " » ");

Explode the string using your divider to create an array of string parts.

$string_parts = explode(" » ", $string);

Filter out any empty array parts.

$string_parts = array_filter( $string_parts );

Recombine using your divider.

$string = implode(" » ", $string_parts);

Then combine them all together to create my one line solution at the top. The code you have using substring will get the job done, but it’s not the way I’d do it.