I have this code of javascript
echo '<script type="text/javascript">';
echo 'document.write('<a style="display:block;width:100%;height:1px;" class="aff-ad-none"></a>');
window.AFF_ONLOAD = window.AFF_ONLOAD || [];window.AFF_ONLOAD.push({lkid:"11",affid:"10",size:"728*90",type:"1",language:"English",web_id:"40",version:110});
var aff_s = document.createElement("script"),aff_h = document.getElementsByTagName("head")[0];aff_s.charset = "utf-8";aff_s.async = !0;aff_s.src = "https://js.affasi.com/affasi_js.min.js";
aff_h.insertBefore(aff_s, aff_h.firstChild);
</script>';
I get Parse error: parse error, expecting ','' or';''
The error is in this line :
echo 'document.write('<a style="display:block;width:100%;height:1px;" class="aff-ad-none"></a>'); ....
How do i add single quote in echo command? This should fix the error i guess right?
5 Answers 5
You need to escape the parentheses ' with \ in document.write() like this:
<?php
echo '<script type="text/javascript">';
echo 'document.write(\'<a style="display:block;width:100%;height:1px;" class="aff-ad-none"></a>\');
window.AFF_ONLOAD = window.AFF_ONLOAD || [];
window.AFF_ONLOAD.push({lkid:"11",affid:"10",size:"728*90", type:"1",language:"English",web_id:"40",version:110});
var aff_s = document.createElement("script"),aff_h =
document.getElementsByTagName("head")[0];aff_s.charset = "utf-8";aff_s.async =
!0;aff_s.src = "https://js.affasi.com/affasi_js.min.js";
aff_h.insertBefore(aff_s, aff_h.firstChild);
</script>';
?>
2 Comments
- you you need to escape charcter (the best way)
echo 'document.write(\'<astyle="display:block;width:100%;height:1px;" class="aff-ad-none"></a>\'); '
you can put the string in a variable like
$var ='<a style="display:block;width:100%;height:1px;" class="aff-ad-none"></a>' ; echo 'document.write('.$var.');'the third way is to cut string into 3 segmant and concat them
echo 'document.write('.'<a style="display:block; width: 100%" ></a>'.');'
Comments
You need to use double quote inside your single quote.
echo '<script type="text/javascript">';
echo 'document.write("<a style="display:block;width:100%;height:1px;" class="aff-ad-none"></a>");
window.AFF_ONLOAD = window.AFF_ONLOAD || [];window.AFF_ONLOAD.push({lkid:"11",affid:"10",size:"728*90",type:"1",language:"English",web_id:"40",version:110});
var aff_s = document.createElement("script"),aff_h =
document.getElementsByTagName("head")[0];aff_s.charset = "utf-8";aff_s.async = !0;aff_s.src = "https://js.affasi.com/affasi_js.min.js";
aff_h.insertBefore(aff_s, aff_h.firstChild);
</script>';
You can also escape your single quote using a \ like so : \'
4 Comments
You can use EOT :
$string = <<<EOT
<script type="text/javascript">
document.write('<a style="display:block;width:100%;height:1px;" class="aff-
ad-none"></a>');
window.AFF_ONLOAD = window.AFF_ONLOAD || [];
window.AFF_ONLOAD.push({lkid:"11",affid:"10",size:"728*90", type:"1",language:"English",web_id:"40",version:110});
var aff_s = document.createElement("script"),aff_h =
document.getElementsByTagName("head")[0];aff_s.charset = "utf-8";aff_s.async =
!0;aff_s.src = "https://js.affasi.com/affasi_js.min.js";
aff_h.insertBefore(aff_s, aff_h.firstChild);
</script>
EOT;
echo $string;
Comments
Try the following.
<script type="text/javascript">document.write('<a style="display:block;width:100%;height:1px;" class="aff-ad-none"></a>');window.AFF_ONLOAD = window.AFF_ONLOAD || [];window.AFF_ONLOAD.push({lkid:"13172240",affid:"10068701",size:"300*250",type:"1",language:"en",web_id:"40",version:110});var aff_s = document.createElement("script"),aff_h = document.getElementsByTagName("head")[0];aff_s.charset = "utf-8";aff_s.async = !0;aff_s.src = "https://js.affasi.com/affasi_js.min.js";aff_h.insertBefore(aff_s, aff_h.firstChild);</script>
1 Comment
lkid and affid, which seems... suspicious.