【问题标题】:Can i display url Directory name我可以显示 url 目录名称吗
【发布时间】:2017-11-26 20:55:54
【问题描述】:

请帮忙。 我的网站有一个错误,没有找到页面。如果一些搜索 http://example.com/example。 我怎样才能像这样在我的错误页面中显示? “未找到示例” 或者如果有人搜索,http://example.com/test 我怎样才能在我的错误页面中显示这样的消息? “未找到测试”

【问题讨论】:

  • 你问的是页面的设计/风格吗?
  • 我可以显示 url 目录名称吗?

标签: php url directory display


【解决方案1】:

您可以使用类似这样的方式提取 URL 路径

<?php
//http://example.com/example
$path = trim(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), "/");
echo htmlspecialchars($path) . " not found";
//will output "example not found";

如果您只需要提取路径的第一个目录

$firstDirectory = explode("/", $path)[0];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    相关资源
    最近更新 更多