Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert Google Adsense Code in PHP script?

Tags:

php

adsense

How to echo AdSense code with PHP? Here is the sample of my code which I am working for a codeigniter php.

$adsence = " 

<div class=\"right-inner\">
            <center width=\"96% class=\"img-responsive center-block\">
                            <script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>

<!-- quiz_net -->
              <ins class=\"adsbygoogle\"
                 style=\"display:block\"
                 data-ad-client=<?php echo $client ?>
                 data-ad-slot=<?php echo $slot ?>
                 data-ad-format=\"auto\"></ins>
              <script>
              (adsbygoogle = window.adsbygoogle || []).push({});
              </script>
            </center>     
</div>";

echo $adsence;

All I want to insert adsense code inside a div with PHP. I also tried with htmlentities along with stripslashes but ad in not getting displayed.

like image 627
El Bachir Argoub Avatar asked Sep 25 '22 05:09

El Bachir Argoub


1 Answers

data-ad-client=<?php echo $client ?>

you're already in the php parser, don't need to open it again

data-ad-client=$client

fix the other spot where u did that too


$adsence = " 
<div class=\"right-inner\">
            <center width=\"96% class=\"img-responsive center-block\">
                            <script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>

<!-- quiz_net -->
              <ins class=\"adsbygoogle\"
                 style=\"display:block\"
                 data-ad-client=\"$client\"
                 data-ad-slot=\"$slot\"
                 data-ad-format=\"auto\"></ins>
              <script>
              (adsbygoogle = window.adsbygoogle || []).push({});
              </script>
            </center>     
</div>";

echo $adsence;
like image 64
I wrestled a bear once. Avatar answered Nov 01 '22 10:11

I wrestled a bear once.