-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?

9
  • So what's on line 60? It looks like you just have a syntax error in your PHP file. Oct 20, 2015 at 22:55
  • The code you linked to doesn't even have 60 lines.
    – melpomene
    Oct 20, 2015 at 22:55
  • My crystal ball says: You're doing echo '...' with a string that also contains single quotes ({ 'key' : ...}).
    – melpomene
    Oct 20, 2015 at 22:56
  • I mean that's the original file without ad code, please Check That Pan now, I've edited it with full Head.php File with ad inside Oct 20, 2015 at 23:00
  • As you can see, I,m not good with javascript, Can you tell me What should i change to make that work ? Oct 20, 2015 at 23:02

1 Answer 1

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>

Not the answer you're looking for? Browse other questions tagged or ask your own question.