Skip to content Skip to sidebar Skip to footer

Php Function To Echo Javascript String

Is the a proper php function to echo javascript string? I want to the php function to echo something like this: &

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;

Solution 3:

There is nothing specific or only for JavaScript but every output feature works for JavaScript. You can just print the out of <?php ?> tag like

<?php 
session_start(); //just an example PHP code
?>
<!--/* 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>

Post a Comment for "Php Function To Echo Javascript String"