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?

asked Jan 28, 2018 at 0:14

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>';
?>
answered Jan 28, 2018 at 0:21
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>'.');'

answered Jan 28, 2018 at 0:39

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 : \'

answered Jan 28, 2018 at 0:20

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;
answered Jan 28, 2018 at 0:26

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>
Tanner Babcock
3,3606 gold badges23 silver badges23 bronze badges
answered Feb 24, 2018 at 2:30

1 Comment

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.