在PHP中的if语句中添加语法

时间:2017-08-07 01:42:33

标签: php

我想将这些代码添加到php中的if语句中。可以吗?

<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";
?>

可以这样做是因为我想根据设备监视器的分辨率在幻灯片中显示不同的图像横幅。感谢

1 个答案:

答案 0 :(得分:-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(尤其是评论#1)