php function to echo javascript string

Solution:1

Use the heredoc-syntax.

Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped […].

Solution:2

Use HEREDOC:

$a=<<<BLA
<!--/* OpenX Interstitial or Floating DHTML Tag v2.8.7 */-->
<script type="text/javascript">// <![CDATA[
//<![CDATA[
var ox_u = 'extremely_long_url_string';
if (document.context) ox_u += '&context=' + escape(document.context);
document.write("<scr"+"ipt type='text/javascript' src='" + ox_u + "'></scr"+"ipt>");
//
// ]]></script>
BLA;

and then you can simply

echo $a;