我正在做一个像这样的目录结构的页面
/ 2017/05/14 /
我在使用head部分定义BASE URL之后使用变量获取当前年,月和日,该部分正常运行。但是当我尝试将这些路径值分配给另一个变量时,它会打印变量名而不是值。
我需要在$ required_year,$ required_month,$ required_day的帮助下定义BASE_URL或BASE_PATH,并且需要包含一些文件,具体取决于此BASE_URL
我希望我已经解释了我想要的东西。
包含一些php文件,具体取决于构造的BASE_URL
<?php
$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$required_year = $_GET['Year'];
$required_month = $_GET['Month'];
$required_day = $_GET['Day'];
define('BASE_URL', '"http://" . $host . "/" . $required_year . "/" . $required_month . "/" . $required_day . "/"');
define('BASE_PATH', '/echo $required_year/echo $required_month/echo $required_day . "/"');
$wowURL = '"http://" . $host . "/" . $required_year . "/" . $required_month . "/" . $required_day . "/"';
?>
<html>
<head>
<base href="http://basharatnews.localhost/<?php echo $required_year ?>/<?php echo $required_month ?>/<?php echo $required_day ?>/"/>
</head>
<?php
echo 'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo $wowURL;
?>
答案 0 :(得分:1)
你不能在''
中创建变量,这会将变量名称变为字符串,而不是它的值。
'"http://" . $host . "/" . $required_year . "/" . $required_month . "/" . $required_day . "/"'
应该是
"http://" . $host . "/" . $required_year . "/" . $required_month . "/" . $required_day . "/"