Welcome to PHPBuilder! When posting PHP code, please use the board's [noparse]
..
[/noparse] bbcode tags as they make your code much easier to read and analyze.
As for your problem, you're using double quoted strings, which means that the backslash has a special meaning (e.g. "\n" gets translated into the new line character).
Either escape your backslash, so that PHP knows you want a literal backslash and aren't starting a special escape sequence, or switch to using single quotes as the string delimiter, since PHP doesn't look for these escape sequences in such strings.
See the manual page for a [man]string[/man] for more info/examples.