spacepoet Posted January 23, 2011 Share Posted January 23, 2011 Hello: I have this snippet of code that will write the current year onto a page if it's embedded on the page itself: <?php echo date("Y") ?> Works fine. But, when I include it in an included file and pull it onto the page with a function, it does not work. Like this: MyNav.php <?php function spFooter() { $spFooter = " <p> © <?php echo date(\"Y\") ?> </p> "; return $spFooter; } ?> MyPage.php <?php include('include/myNav.php'); ?> <html> ... <?php echo spFooter(); ?> ... </html> What is the proper way to do this, and also what are the basic rules for properly nesting PHP scripts like this? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/225409-how-to-write-date-script-into-a-function/ Share on other sites More sharing options...
Zurev Posted January 23, 2011 Share Posted January 23, 2011 I'd probably do something more like this: function spFooter() { $spFooter ="<p> ©"; $spFooter .= date("Y"); $spFooter .= "</p>"; return $spFooter; } First, you're including <?php tags while you're in a php script, and you're echo'ing within a variable? Your way of doing it would be this: function spFooter() { $spFooter = " <p> © ". date('Y')." </p> "; return $spFooter; } Link to comment https://forums.phpfreaks.com/topic/225409-how-to-write-date-script-into-a-function/#findComment-1164026 Share on other sites More sharing options...
spacepoet Posted January 23, 2011 Author Share Posted January 23, 2011 Excellent! Thank you very much. So, to nest other scripts in PHP blocks, they get encased in a QUOTE PERIOD script here PERIOD QUOTES? ". script here ." Correct? Link to comment https://forums.phpfreaks.com/topic/225409-how-to-write-date-script-into-a-function/#findComment-1164033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.