簡體   English   中英

如何在PHP腳本中插入Google Adsense代碼?

[英]How to insert Google Adsense Code in PHP script?

如何使用PHP回復AdSense代碼? 這是我為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;

我只想用PHP在div中插入adsense代碼。 我也試過htmlentities和striplashes但廣告沒有顯示。

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

你已經在php解析器中,不需要再次打開它

data-ad-client=$client

修復你在那里做的另一個地方


$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;

我添加了我的想法,我希望它對你有用。

如果您有托管站點,則可以在數據庫中使用查詢,也可以使用配置文件來始終不利用源代碼。

喜歡:

// config_file.php

$adsense = "0"; // 0 - For unactivate , 1 - For activate
$ads_client_id = "ca-pub-1234567890123456"; // Publisher ID
$ads_slot_id   = "123456789"; // Slot ID
$ads_format    = "auto"; // ADS format - auto (This ad unit can automatically adjust the size of space available on the page.)

//代碼嵌入

<?php if($adsense == 1){
echo "<script async src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>
<ins class=\"adsbygoogle\"
     style=\"display:block\"
     data-ad-client=\"{$ads_client_id}\"
     data-ad-slot=\"{$ads_slot_id}\"
     data-ad-format=\"{$ads_format}\"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>";
}
?>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({
          google_ad_client: "ca-pub-1325790438113768",
          enable_page_level_ads: true
     });
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM