嗨,我想知道我可能做错了什么.我有两个条件返回true或false.出于同样的原因它不起作用.如果有人指出我可能做错了什么,我将不胜感激.
<?php
$pagetype = strpos($currentPage, 'retail');
if(isset($quoterequest) && $pagetype === True && $currentPage !== 'index.php'){
echo "this is retail" ;
}elseif(isset($quoterequest) && $pagetype === False && $currentPage !== 'index.php'){
echo "this is restaurant";
}
?>
Run Code Online (Sandbox Code Playgroud)
编辑 - 抱歉我编辑它但由于某种原因没有出现.基本上,如果发现它,脚本会查看网址"零售",如果不是"这是餐厅",它应该返回"这是零售"
quoterequest只是一个变量
$quoterequest = "washington"
Run Code Online (Sandbox Code Playgroud)
并且当前页面来自
<?php $currentPage = basename($_SERVER['SCRIPT_NAME']);
Run Code Online (Sandbox Code Playgroud)
只是为了清楚.网址是这样的结构
www.example.com/retail-store.php www.example.com/store.php
$pageType从来都不是真的.如果包含字符串,则strpos返回一个整数.所以测试一下!== false.
<?php
$pagetype = strpos($currentPage, 'retail');
if (isset($quoterequest) && $currentPage !== 'index.php') {
if ($pagetype !== false) {
echo "this is retail";
}
else {
echo "this is restaurant";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
196 次 |
| 最近记录: |