1

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

2

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>';
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer as well. It seems that i get the correct output and i have no error but the content of the javascript does not show up in the webpage! Weird!
anyway i accept this answer it works with the new code generated probably the previous content was offline.
1
  • 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

0

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

Thanks for your answer i got the output like this: <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:"11599254",affid:"10054952",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 = "js.affasi.com/affasi_js.min.js"; aff_h.insertBefore(aff_s, aff_h.firstChild); </script> with \'
But cant see the output in the webpage for some reason! That is weird!
Well i can't help you with your Javascript. i don't have any context.
It was probably the content offline. I added a new one and it works thanks for your help!
0

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

-1

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

This doesn't answer the question. It also changes the values of lkid and affid, which seems... suspicious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.