PHP 切换大小写 URL
我们目前使用 Switch case url 配置来帮助我们在某些 url 上进行导航,我不确定是否有更简单的方法来做到这一点,但我似乎找不到 1。
<?php if (! isset($_GET['step']))
{
include('./step1.php');
} else {
$page = $_GET['step'];
switch($page)
{
case '1':
include('./step1.php');
break;
case '2':
include('./step2.php');
break;
}
}
?>
现在这个系统工作完美,但我们遇到的唯一障碍如果他们输入 xxxxxx.php?step=3 繁荣,他们只会得到一个空白页,这应该是正确的,因为它没有处理“3”的情况,但我想知道的是..有没有任何 php 代码我可以添加到底部这可能会告诉它除了这 2 种情况之外的任何情况,将其重定向回 xxxxx.php ?
谢谢
丹尼尔
We currently use Switch case url config to help us with the navigation on some of our urls, Im not sure if there is an easier way to do it but i couldnt seem to find 1.
<?php if (! isset($_GET['step']))
{
include('./step1.php');
} else {
$page = $_GET['step'];
switch($page)
{
case '1':
include('./step1.php');
break;
case '2':
include('./step2.php');
break;
}
}
?>
Now this system works perfectly but the only snag we hit is if they type in xxxxxx.php?step=3 boom they just get a blank page and that should be correct as there is no case for it to handle '3' but what i was wondering is .. is there any php code i could add to the bottom that may tell it for any case other than those 2 to redirect it back to xxxxx.php ?
Thanks
Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
default
情况。也就是说,将您的开关更改为如下所示:对于未明确指定的每种情况,都将执行默认情况。
Use the
default
case. That is, change your switch to something like this:The default case will be executed for every case which is not explicitly specified.
所有
switch
语句都允许一个default
情况,如果没有其他情况发生,该情况就会触发。像...之类的东西会起作用。但是,您可能希望通过 Google 搜索其他更强大且可扩展的页面调度解决方案。
All
switch
statements allow adefault
case that will fire if no other case does. Something like...would work. You may, however, want to Google around for other, more robust and extensible, page dispatch solutions.
采取不同的方法怎么样:
How about a different approach with something along the lines of: