2017-08-07 61 views
-4

我想将这些代码添加到if语句中。可以做到吗?将语法添加到if语句中PHP

<script> 
$(function() { 
    "use strict"; 
    $('#first_container').vegas({ 
     color: '<?php echo $wa[custom_79];?>', 
     delay: <?php echo $wa[custom_80];?>, 
     transitionDuration: <?php echo $wa[custom_133];?>, 
     timer: false, 
     transition: null, 
     slides: [ 
      <?php if ($wa[custom_82] != "" && $wa[custom_83] == "1") { $wa[custom_82] = str_replace(' ', '%20', $wa[custom_82]);?> 
       {src: '<?php echo $wa[custom_82];?>'}, 
      <?php } 
      if ($wa[custom_84] != "" && $wa[custom_85] == "1") { $wa[custom_84] = str_replace(' ', '%20', $wa[custom_84]);?> 
       {src: '<?php echo $wa[custom_84];?>'}, 
      <?php } 
      if ($wa[custom_86] != "" && $wa[custom_87] == "1") { $wa[custom_87] = str_replace(' ', '%20', $wa[custom_87]);?> 
       {src: '<?php echo $wa[custom_86];?>'}, 
      <?php } 
      if ($wa[custom_88] != "" && $wa[custom_89] == "1") { $wa[custom_89] = str_replace(' ', '%20', $wa[custom_89]);?> 
       {src: '<?php echo $wa[custom_88];?>'}, 
      <?php } 
      if ($wa[custom_90] != "" && $wa[custom_91] == "1") { $wa[custom_91] = str_replace(' ', '%20', $wa[custom_91]);?> 
       {src: '<?php echo $wa[custom_90]?>'}, 
      <?php } 
      if ($wa[custom_92] != "" && $wa[custom_93] == "1") { $wa[custom_93] = str_replace(' ', '%20', $wa[custom_93]);?> 
       {src: '<?php echo $wa[custom_92]?>'}, 
      <?php } 
      if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
       {src: '<?php echo $wa[custom_94];?>'}, 
      <?php } 
      ?> 
      <? if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
       {src:'images/1-Hov-Lean-1800px-X600px.jpg'}, 
      <? } ?> 
      <? if ($wa[custom_96] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
       {src:'images/1-Angkor-1800px-X-600px.jpg'}, 
      <? } ?> 
      <? if ($wa[custom_98] != "" && $wa[custom_95] == "1") { $wa[custom_97] = str_replace(' ', '%20', $wa[custom_97]);?> 
       {src:'images/Home-Pages-Angkor-PC.png'}, 
      <? } ?> 
      {src:'images/Home-Pages-Peakbond.png'} 
     ], 
</script> 

<?php if ($wa[custom_132] == "1") { ?> 
    <a href="#" class="previous hidden-xs" style="visibility: visible;"></a> 
    <a href="#" class="next hidden-xs" style="visibility: visible;"></a> 
<?php } ?> 

它应该是这样的

<?php 
if($_COOKIE["size"]>800) 
    echo "I want to put those code inside here"; 
else 
    echo "Not decide yet"; 
?> 

可以这样做,因为我想在显示基于设备的显示器分辨率的幻灯片不同的图像旗帜。谢谢

+0

你在哪里设置cookie?你在哪里使用横幅? – chris85

+0

我在JavaScript中设置了cookie。 – Iqmal

回答

-1

这是你在追求什么?如果不是,请澄清您的要求并更正您问题中的语法错误。

<?php if($_COOKIE["size"]>800) { 
    echo '<script>var iqmal = true;</script>'; 
    if ($wa[custom_132] == "1") { 
     echo ' 
      <a href="#" class="previous hidden-xs" style="visibility: visible;"></a> 
      <a href="#" class="next hidden-xs" style="visibility: visible;"></a> 
     '; 
    } 
?> 

<script> 
$(function() { 
    "use strict"; 
    if(iqmal) { 
     $('#first_container').vegas({ 
      color: '<?php echo $wa[custom_79];?>', 
      delay: <?php echo $wa[custom_80];?>, 
      transitionDuration: <?php echo $wa[custom_133];?>, 
      timer: false, 
      transition: null, 
      slides: [ 
       <?php if ($wa[custom_82] != "" && $wa[custom_83] == "1") { $wa[custom_82] = str_replace(' ', '%20', $wa[custom_82]);?> 
        {src: '<?php echo $wa[custom_82];?>'}, 
       <?php } 
       if ($wa[custom_84] != "" && $wa[custom_85] == "1") { $wa[custom_84] = str_replace(' ', '%20', $wa[custom_84]);?> 
        {src: '<?php echo $wa[custom_84];?>'}, 
       <?php } 
       if ($wa[custom_86] != "" && $wa[custom_87] == "1") { $wa[custom_87] = str_replace(' ', '%20', $wa[custom_87]);?> 
        {src: '<?php echo $wa[custom_86];?>'}, 
       <?php } 
       if ($wa[custom_88] != "" && $wa[custom_89] == "1") { $wa[custom_89] = str_replace(' ', '%20', $wa[custom_89]);?> 
        {src: '<?php echo $wa[custom_88];?>'}, 
       <?php } 
       if ($wa[custom_90] != "" && $wa[custom_91] == "1") { $wa[custom_91] = str_replace(' ', '%20', $wa[custom_91]);?> 
        {src: '<?php echo $wa[custom_90]?>'}, 
       <?php } 
       if ($wa[custom_92] != "" && $wa[custom_93] == "1") { $wa[custom_93] = str_replace(' ', '%20', $wa[custom_93]);?> 
        {src: '<?php echo $wa[custom_92]?>'}, 
       <?php } 
       if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
        {src: '<?php echo $wa[custom_94];?>'}, 
       <?php } 
       ?> 
       <? if ($wa[custom_94] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
        {src:'images/1-Hov-Lean-1800px-X600px.jpg'}, 
       <? } ?> 
       <? if ($wa[custom_96] != "" && $wa[custom_95] == "1") { $wa[custom_95] = str_replace(' ', '%20', $wa[custom_95]);?> 
        {src:'images/1-Angkor-1800px-X-600px.jpg'}, 
       <? } ?> 
       <? if ($wa[custom_98] != "" && $wa[custom_95] == "1") { $wa[custom_97] = str_replace(' ', '%20', $wa[custom_97]);?> 
        {src:'images/Home-Pages-Angkor-PC.png'}, 
       <? } ?> 
       {src:'images/Home-Pages-Peakbond.png'} 
      ] 
     }); 
    } 
}); 
</script> 

此处了解详情:http://php.net/manual/en/control-structures.if.php(ESP见注释#1)

+0

恐怕它不适合我。你可以请我给我看看。我尝试过,但它不起作用。 – Iqmal

+0

请参阅上面的修改。 – Aydin4ik

+0

嗨艾登,我已经算出了syntaxt。感谢您的时间和答复。真的很高兴。干杯。 – Iqmal