<?php
echo "PHP:\n";
// echo "1: \", "\n"; - syntax error
echo "2: \\", "\n"; // outputs \
// echo "3: \\\", "\n"; - syntax error
echo "4: \\\\", "\n"; // outputs \\
// echo "5: \\\\\", "\n"; - syntax error
echo "6: \\\\\\", "\n"; // outputs \\\
// echo "7: \\\\\\\", "\n"; - syntax error
echo "8: \\\\\\\\", "\n"; // outputs \\\\
echo "\nPHP + PCRE:\n";
// skipping odd counts because they're all syntax errors
echo "2: ", preg_replace('/^/', '\\', ""), "\n"; // PCRE receives \ and allows it as a lone \ -> output \
echo "4: ", preg_replace('/^/', '\\\\', ""), "\n"; // PCRE receives \\ and interprets it as \ -> output \
echo "6: ", preg_replace('/^/', '\\\\\\', ""), "\n"; // PCRE receives \\\ and interprets it as \ + lone \ -> output \\
echo "8: ", preg_replace('/^/', '\\\\\\\\', ""), "\n"; // PCRE receives \\\\ and interprets it as \\ -> output \\
preferences:
52.35 ms | 402 KiB | 5 Q