我必须开发一个符合某些逻辑的代码
这里
count($ replylies) - 计算页面上的总回复
$ replynumber - 根据所做的回复总数,每个回复是1,2,3,4,5,6,7,8,9,10,11,12,13,14,15等。用户在帖子中
我试图根据回复显示基于adsense和其他广告脚本的自定义广告脚本
<?php
if( count( $replies ) <= 3 )
{
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ad-->
<ins class="google"
style="display:inline-block;width:200px;height:90px"
data-ad-client="ca-pub-xxxxx"
data-ad-slot="xxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
}
else if(((count( $replies ) > 3) and (count( $replies ) <= 6)) and ($replynumber == '1','3','5'))
{
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ad2-->
<ins class="google"
style="display:inline-block;width:200px;height:90px"
data-ad-client="ca-pub-xxxxx"
data-ad-slot="xxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
}
else if(((count( $replies ) > 6) and (count( $replies ) <= 12)) and ($replynumber == '1','4','7','10'))
{
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ad3-->
<ins class="google"
style="display:inline-block;width:200px;height:90px"
data-ad-client="ca-pub-xxxxx"
data-ad-slot="xxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script> }
}
else if( count( $replies ) > 12 )
{
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ad4-->
<ins class="google"
style="display:inline-block;width:200px;height:90px"
data-ad-client="ca-pub-xxxxx"
data-ad-slot="xxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
}
?>
但这会导致解析错误 请任何人帮忙吗
答案 0 :(得分:1)
是因为php可以解析de script标签。你需要像这样关闭de php吗?&gt;在脚本之前,他们再次打开它或用回声打印它,例如: 选项1:
if( count( $replies ) <= 3 )
{
?>
<script>
Script 1 to display
</script>
<?php
}
选项2:
<?php
if( count( $replies ) <= 3 )
{
echo " <script>
Script 1 to display
</script>";
}