Jump to content

How to write DATE script into a Function ??


spacepoet

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.