gpt4 book ai didi

php - 如果在 php 脚本中有其他条件

转载 作者:行者123 更新时间:2023-11-28 12:08:35 25 4
gpt4 key购买 nike

我正在尝试修改 this codecanyon 提供的搜索引擎脚本。在这里我可以看到类似

的代码
<div class="{$contentClass}">

<div class="resultarea" style="width:55%;float:left;">
{$content}
</div>

</div>

这里如果$contentClass="mainpage"我需要将宽度设置为100%并且想将其他页面的宽度设置为55%。

我试过下面的代码

<div class="{$contentClass}">

<div class="resultarea" <?php if ($contentClass=="mainpage"){?> style="width:100%;float:left;" <?php }else{?>style="width:100%;float:left;"<?php} ?>>
{$content}
</div>

我认为 PHP 代码在这里不起作用,我可以打印 contentClass 的值而无需提供 php echo 语句作为 {$contentClass}。我不确定这里使用的框架,请帮助我解决这个问题。

请检查我的工作here

最佳答案

这行不通吗?

<div class="resultarea" <?php if ($contentClass=="mainpage"){?> style="width:100%;float:left;" <?php }else{?>style="width:50%;float:left;"<?php} ?>>

如果您查看 else block 中的 CSS,您会发现您将宽度设置为 100%。基本上,无论 $contentClass=="mainpage" 与否,您的 CSS 都是相同的。

您的 IF 语句实际上没有做任何事情:

<?php if ($contentClass=="mainpage"){?> 
style="width:100%;float:left;"
<?php }else{?>
style="width:100%;float:left;"
<?php} ?>>

关于php - 如果在 php 脚本中有其他条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19609263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com