我正在使用 magento,我想显示一个 div,具体取决于我是否处于特定 View 中。我使用以下内容:
<?php
$url1 = (string)$this->getBaseUrl()."home_tienda";
$url2 = (string)$this->getUrl('*/*/*',array('_current'=>true, '_use_rewrite'=>true));
?>
如果我输入 $url1 和 $url2 的“var_dump”,我将获得以下内容:
string(28) "http://127.0.0.1/home_tienda"
string(37) "http://127.0.0.1/home_tienda"
嗯,我已经尝试过这个:
<?php if (strcmp($url1,$url2)==0):?>
<div class="clsbanner"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_banner')->toHtml(); ?></div>
<?php endif?>
我也尝试过这个:
<?php if ($url1==$url2):?>
<div class="clsbanner"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_banner')->toHtml(); ?></div>
<?php endif?>
在这两个过程中我都得到了 false,所以我的 div 没有显示,而我需要显示它
最佳答案
请使用 ===
运算符重试 strcmp()
和/或 stricmp()
。另一个有用的工具是 stripos()
,它会从 URL 比较中返回 0,但如果未找到字符串,则会返回 FALSE。
0 == FALSE
测试相同...
但是
0 === FALSE
将捕获您正在查找的条件,因为 ===
也匹配数据类型。
关于php - 比较 Magento .phtml 文件中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11121806/