Quote:
Originally Posted by YellowPages
This might be a dumb question, but how can I write this?
PHP Code:
<? include '/<? echo date("d"); ?>.html'; ?>
That would display /08.html
Thank you,
YP
|
That question was really confusingly worded!
Quote:
Originally Posted by StuartD
<?
$filename = "/".date('d').".html";
include $filename;
?>
|
Good answer. Explanation:
Firstly, understand that "
" indicates the START of PHP code and
indicates the END of the PHP code section. So your first error was to put a START inside another START. (
)
If you got rid of the first error you would be at:
PHP Code:
<? include echo date('d') .html ?>
now your second error is this... ".html" - "echo" means to "print" or "output" or send it to the browser. So you are telling it to send "date('d')" to the browser and then send .html. You literally want it to send ".html" so put it in quotes... so now you have
PHP Code:
<? include echo date('d') ".html" ?>
Next you have the problem that you are telling it to echo two things (1) date and (2) ".html" you need to use the "AND" symbol, which is a period: "." So now you are up to
PHP Code:
<? include echo date('d').".html" ?>
finally you have the problem of giving two COMMANDS. "include" is a command telling PHP to include an external file. and "echo" is a command telling PHP to output something. You have to get rid of one of em... or break them into two lines. In this case you don't really want "echo" because the string you are creating (date('d) + ".html") doesn't need to go out to the browser, it just needs to be sent to the command "include". So just get rid of "echo"
PHP Code:
<? include date('d').".html" ?>
that should work.
if it doesn't work, then break it down like Stuart did. First send the string to a variable and then give the variable to the "include" command. the variable can be anything. Stuart called it "filename"
PHP Code:
<?
$filename = date('d').".html";
include $filename
?>
I don't know why i spent so much time explaining this... but I hope you and others find it useful. Sometimes we just want a quick answer, but if we actually understand the reasons behind why the quick answer we got works... that helps us solve similar problems in the future on our own without needing outside help.