I find that heredocs is pretty poor coding (no offence). The way PHP does this better is to simply just escape the PHP code:
?>say "there i am"<?
which can be put in anywhere in your code.
If you are just curious about slashes, the addslashes() function might be your cup of tea.
Dave