A regex way:
$result = preg_replace('~(?:\G(?!\A)|\A[^\\\]*\\\)[^\\\]*\\\\\K~', '\\\\\\\\\\', $txt);
Note that to figure a literal backslash in a single quoted pattern, you need to use at least 3 backslashes or 4 backslashes for disambiguation (in this case for example \\\\\K). With the nowdoc syntax, only two are needed as you can see in detailed version:
$pattern = <<<'EOD'
~ # pattern delimiter
(?:
\G # position after the previous match
(?!\A) # not at the start of the string
| # OR
\A # start of the string
[^\\]* # all that is not a slash
\\ # a literal slash character
)
[^\\]* \\
\K # discard all on the left from the match result
~x
EOD;
Without regex:(maybe more efficient):
$chunks = explode('\\', $txt);
$first = array_shift($chunks);
$result = $first . '\\'. implode('\\\\\\\\', $chunks);