dtvpl739577 2011-10-23 17:20
浏览 28

我是否需要使用substr()来显示目录,还是可以使用其他代码?

Everything in this file is set up in a way in which $_GET['q'] brings up the main domain name and the other directories in the website are brought up in this manner: else if (substr($_GET['q'], 0, 7) == 'quotes/') If I wanted to have a folder called: ultimate-deals-and-low-prices, would I use

else if (substr($_GET['q'], 0, 30) == 'ultimate-deals-and-low-prices/')

Does that make sense, or would I call my directory in another manner, without having to ask php to call a substring of the directory file name. I understand that is what substring does, but I've only seen it be used for characters less than 10. If my directory has more characters, would I still use substring?

This is the beginning of the if statement in this document:

require_once(getcwd() ."/db/db_pagetitle.php");
print get_page_title($_GET['q']);
if (isset($_GET['q']) && $_GET['q']) {
    if (file_exists(getcwd() .'/pages/'. $_GET['q'] .'.php')) {
        require_once(getcwd() .'/pages/'. $_GET['q'] .'.php');

than it goes into

else if (substr($_GET['q'], 0, 7) == 'quotes/') 

How do I call my directory?

Thanks?

  • 写回答

3条回答 默认 最新

  • dpub33855 2011-10-23 17:44
    关注

    You can still use substr, there's no problem with having more than 10 characters :) In other words, you can use exactly the code you've posted (if you don't mind the typing): else if (substr($_GET['q'], 0, 30) == 'ultimate-deals-and-low-prices/')

    But, if there is some of common logic for all folders (like, cd-ing into it or searching for a file in it) you don't have to write an else branch for each folder, you can just use something like:

    if (isset($_GET['q']) && $_GET['q']) {
        if (file_exists(getcwd() .'/pages/'. $_GET['q'] .'.php')) {
            require_once(getcwd() .'/pages/'. $_GET['q'] .'.php');
        } else if (is_dir(getcwd() . '/pages/' . $_GET['q'])) {
            // do whatever you want to do with the folder
        }
    }
    

    If you would write more of your code it'd be easier to understand what you're trying to do.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向