-2

I'm now thinking to put some ad in my website. Above all Adsterra seems nice for me. I registered there and get some code to display their ad on my site.

The code looks like this:

<script type="text/javascript">
atOptions = {
    'key' : '0000',
    'format' : 'iframe',
    'height' : 250,
    'width' : 300,
    'params' : {}
};
document.write('<scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.example.com/invoke.js"></scr' + 'ipt>');

I placed in on my WordPress blog and its fine, but when in my other php made part, this made my those sections blank or gave an error.

I checked the error Log file and it was:

PHP Parse error: syntax error, unexpected 'key' (T_STRING), expecting ',' or ';' in /home/fajlamic/public_html/links/inc/head.php on line 60

I added my whole head.php file in a pan >> http://codepen.io/anon/pen/mepqEq

I've done some Google searching and also in StackOverflow but nothing seemed to work for me. Can anyone tell me how I can revise what I have so it works properly?

Rasclatt
  • 12,498
  • 3
  • 25
  • 33

1 Answers1

0

Two things you can do. 1) Stop the <?php before you start your <style> on down to the bottom of the page, or 2) Escape all the javascript single quotes:

Option 1: Escaping

'<script type="text/javascript">
    atOptions = {
        \'key\' : \'61aeec1e4ef0ef989337d9ed0f8800be\',
        \'format\' : \'iframe\',
        \'height\' : 250,
        \'width\' : 300,
        \'params\' : {}
    };
    document.write(\'<scr\' + \'ipt type="text/javascript" src="http\' + (location.protocol === \'https:\' ? \'s\' : \'\') + \'://www.bnhtml.com/invoke.js"></scr\' + \'ipt>\');
</script>';

Options 2: Stop php

'<meta name="Robots" content="All,Index,Follow">';
// Stop php here since you don't have anymore php-generated variables below this part
?>
<!-- start html here -->
<style>
Rasclatt
  • 12,498
  • 3
  • 25
  • 33