I'll show you something...
<?
$my_variable = "my_value";
echo "Hello !";
?>
Is the same thing than :
<?
$my_variable = "my_value";
?>
Hello !
It works in everything : while, for, if, etc.
Ex :
<?
$number = 1;
if($number == 0) {
?>
Number : 0
<?
} else {
?>
Number != 0
<?
}
?>
So you can use that method to echo your JavaScript...
<?
php code...
?>
<SCRIPT LANGUAGUE="JavaScript">
<!--
....
-->
</SCRIPT>
But if you absolutely want to use echo, escape any " to \", any ' to \', any \ to \, any NULL to \NULL (I don't think you have to convert the last one.. !).
If you already have \" in your script => \\" (\ = \, \" = ", \ + " = \").
Hope it helped.
I suggest you to see http://www.php.net/manual/en/function.addslashes.php