Thread: php question
View Single Post
Old 05-08-2008, 11:13 AM  
Hell House Vic
Pay to Cum
 
Hell House Vic's Avatar
 
Join Date: Aug 2004
Location: Nor San Diego
Posts: 1,029
Quote:
Originally Posted by YellowPages View Post
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 View Post
<?
$filename = "/".date('d').".html";
include $filename;
?>
Good answer. Explanation:

Firstly, understand that "
PHP Code:
<?
" indicates the START of PHP code and
PHP Code:
?> 
indicates the END of the PHP code section. So your first error was to put a START inside another START. (
PHP Code:
<? include <?
)

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.
__________________

Contact Me - ICQ: 206851710 eMail vic (at) hellhousemedia (dot) com
'Satanism is like Capitalism for teens' - Ty HellHouse
Hell House Vic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote