duannei0044 2017-07-20 15:54
浏览 45
已采纳

如果php中的Statement导致解析错误

I have to develop a code which meet certain logic

Here

count( $replies ) - calculate total replies on page

$replynumber - is what every reply which is 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 etc based on total number of replies done by users in the post

I am trying to dispaly custom advertising script based on adsense and other ad script depending on replies

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

But this is leading to parse error Can any one help on it please

  • 写回答

1条回答 默认 最新

  • duanchuli5647 2017-07-20 16:00
    关注

    is because php can parse de script tag. You need to close de php like this ?> before the script and them open it again or print it with an echo for example: option 1:

    if( count( $replies ) <= 3 )
    {   
    ?>
     <script>       
     Script 1 to display
     </script>
    <?php
    }
    

    option 2:

    <?php 
    if( count( $replies ) <= 3 )
       {   
        echo "  <script>       
        Script 1 to display
        </script>";
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么