<?php
date_default_timezone_set('America/Los_Angeles'); //set your timezone
$file = file_get_contents('file.txt'); //Get the file
$splitLines = explode("\n", $file); //use \r\n if \n doesn't work (linux and windows differences)
$weeknumber = date("W", strtotime("now")); //Get current weeknumber
$line = $splitLines[($weeknumber -1)]; //get the right line, -1 because week 1 is 0, week 2 = 1, etc. etc.
echo "<p>$line</p>"; //echo the line in the <p> tag
?>
IF you want to do this within html
instead of php
, do it like this:
<body>
<p><?= $line ?></p>
</body>
Tho I do feel like I should tell you, that this is a very bad idea. It's a lot smarter to simply make an array in a seperate php file which you could include or something. Eventually, you might bump into problems with a line-break based structure.
-- You asked me how to execute it instead of doing an echo. I don't know what you mean, but here's a try:
<?php
function getWeekLine(){
date_default_timezone_set('America/Los_Angeles'); //set your timezone
$file = file_get_contents('file.txt'); //Get the file
$splitLines = explode("\n", $file); //use \r\n if \n doesn't work (linux and windows differences)
$weeknumber = date("W", strtotime("now")); //Get current weeknumber
$line = $splitLines[($weeknumber -1)]; //get the right line, -1 because week 1 is 0, week 2 = 1, etc. etc.
Return $line;
}
?>
IF you want to do this within html
instead of php
, do it like this:
<body>
<p><?= getWeekLine() ?></p>
</body>
Now, when you're in need of "execution", just say <?php getWeekLine(); ?>
Use echo
if you want to actually show the results.