Parse error: Really Can't Figure This One Out

NEW ERROR!! Thanks guys! worked, but new error popped up on line 55 :( im gonna edit, and mark the line number with "// LINE 55", in my original post ^^

 Parse error: syntax error, unexpected '.' in C:\wamp\www\flueforumdk\config.php on line 55

I get a parse error when trying to make a function, my timestamp code worked well before i tried to put it in a function so i can re-use it without making a big mess in my code. I get the unix time from a mysql database from 'cmd.php', and have my function in 'config.php' here's my error:

Parse error: syntax error, unexpected ''$UNIX_TIME_SECONDS'' (T_CONSTANT_ENCAPSED_STRING), expecting '&' or variable (T_VARIABLE) in C:\wamp\www\flueforumdk\config.php on line 33

HERE'S MY CODE IN 'CMD.PHP':

$GET_UNIX_STAMP_FROM_DB = $art[tidspunkt];
$UNIX_TIME_SECONDS = $GET_UNIX_STAMP_FROM_DB;

echo timestamp_converter($UNIX_TIME_SECONDS);

AND HERE'S MY CODE IN 'CONFIG.PHP':

## TIMESTAMP CONVERTER FUNCTION
function timestamp_converter('$UNIX_TIME_SECONDS'){
          // UDREGNING FRA UNIX TIME
          $tid = time() - $UNIX_TIME_SECONDS;
          $timer = floor($tid/3600);
          $minutter = floor($tid/60);
          $dage = floor($timer / 24);
          $uge = floor($dage / 7);
          $month = floor($dage / 30.5);
          $aar = floor($dage / 365);
     if($tid < 60){
       echo"<b>$tid</b> sekunder";
     } elseif ($tid > 60){
       echo"";
       } // THIS IS LINE 33
     if($minutter == 0){
       echo"";
     } elseif ($minutter < 60){
     if($minutter == 1){
       echo"<b>$minutter</b> minut";
     }else{
       echo"<b>$minutter</b> minutter";
     }
     }
         if($timer == 0){
       echo"";
     } elseif ($timer < 24){
     if($timer == 1){
       echo"<b>$timer</b> time";
       }else{
echo"<b>$timer</b> timer";
}
}
    //LINE 55   if($dage == 0){
echo"";
} elseif ($dage < 7){
if($dage == 1){
echo"<b>$dage</b> dag";
}else{
echo"<b>$dage</b> dage";
}
}
  if($uge == 0){
echo"";
} elseif ($uge < 4){
if($uge == 1){
echo"<b>$uge</b> uge";
}else{
echo"<b>$uge</b> uger";
}
}
   if($month == 0){
echo"";
} elseif ($month < 12){
if($month == 1){
echo"<b>$month</b> måned";
}else{
echo"<b>$month</b> måneder";
}
}
    if($aar == 0){
echo"";
} elseif ($aar > 0){
if($aar == 1){
echo"<b>$aar</b> år";
}else{
echo"<b>$aar</b> år";
}
}
  }

Answers


The line

function timestamp_converter('$UNIX_TIME_SECONDS'){

must be

function timestamp_converter($UNIX_TIME_SECONDS){

without the quotation marks, as this is the incoming parameter and no concrete value at this point.


Change your function declaration to...

function timestamp_converter($UNIX_TIME_SECONDS){

If your line creating the function, you should only be using single quotes when predefining a variable for the function. This is the only time you need to use quotes like this while declaring a function.

function example ($DATA = 'data') {}
function example ($UNIX_TIME_SECONDS = 'predefine it here if you need to') {}

Need Your Help

Silverlight File Not Found System.Runtime.Serialization on Deserialization from Newtonsoft

c# silverlight exception filenotfoundexception json.net

I am getting an exception when trying to deserialize JSON. It is my understanding that this file is provided by the Silverlight Runtime on the users local file system and should not need to be incl...

Reduced image size in NSScrollView

objective-c nsimage nsscrollview nsimageview

I'm trying to load an image into my NSImageView/NSScrollView and display it at actual size, but the image mysteriously ends up getting displayed at about half-size. I thought at first it might be b...