dougui2254 2015-02-18 05:39
浏览 36
已采纳

PHP根据参数更改目录(来自url的$ GET)

I try to run project and get localhost:8000/fishes.php and then change it to localhost:8000/fishes.php?fish=pike (or trout).

I have directories on same project /info/pike (or trout) and in these directories there is info.txt where first line has fish latin name and second line has average size.

My question is, How can I get text from that file to "site". Code doesn't include html-code, I don't have the code right now with me. But it is fine and runs normally.

Thanks

   <?php
        $species = $_GET["fish"];
        if (file_exists("info.txt")) {
        $array = explode("/n", file_get_contents('$species/info.txt'));
        $name = $array[0];
        $size = $array[1];
        } else {
        }

        global $name;
        global $size;

        ?>


         <h1><?php$name?> (<?php$size?>)</h1>
  • 写回答

4条回答 默认 最新

  • dq_609586475 2015-02-18 05:57
    关注

    In your Markup, you're opening the php tag, and calling a variable. This variable is not actually printing to the STDOUT. You have a few options:

    <?php echo $name; ?>
    

    or

    <?php print $name; ?>
    

    or if you have shorttags enabled

    <?=$name;?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?