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. Quote Link to comment 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; } Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.