View Full Version : T_CONSTANT_ENCAPSED_STRING error

06-17-2006, 10:27 AM

I have been making my own version of an alternate post-date system, where instead of telling you when a post was made, it tells you how long ago it was made, ranging from seconds to, in this case, millennia.

My problem is that I get the following error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in directory\file.php on line 9

when trying to execute the system-thingy I've been working on. Here's the block of code for that:

$posttime1 = $date-$row['date'];
if($posttime1<60) { // 60s = 1 minute
$posttime0 = $posttime1." seconds";
} elseif($posttime1<3600) { //3600s = 1 hour
$posttime0 = $posttime1/60." minutes";
} elseif($posttime1<86400) { //86400s = 1 day
$posttime0 = $posttime1/60/60." hours";
} elseif($posttime1<604800) { //604800s = 1 week
$posttime0 = $posttime1/60/60/24." days";
} elseif($posttime1<2592000) { //2592000s = 1 month (30 days)
$posttime0 = $posttime1/60/60/24/7." weeks";
} elseif($posttime1<31536000) { //31536000s = 1 year (365 days)
$posttime0 = $posttime1/60/60/24/30." months";
} elseif($posttime1<315360000) { //315360000s = 1 decade
$posttime0 = $posttime1/60/60/24/365." years";
} elseif($posttime1<3153600000) { //3153600000s = 1 century
$posttime0 = $posttime1/60/60/24/365/10." decades";
} elseif($posttime1<31536000000) { //31536000000s = 1 millennium
$posttime0 = $posttime1/60/60/24/365/100." centuries";
} elseif($posttime1>31536000000) {
$posttime0 = $posttime1/60/60/24/365/1000." millennia";

Line 9 is the fifth line down in the above code. I realise that this error usually has to do with the code above the line specified, but I can't find what I've done wrong. I've narrowed it down to having something to do with the math, because when I remove the /60 from line 9, it gives me the same error for line 11.

Also, in case it has to do with anything, the first line's $date is the current time in seconds since the Unix Epoch, and $row['date'] is the time the post was made, in the same format.

Any and all help is appreciated. Thanks!

06-17-2006, 12:20 PM
Think spacing!

What you are telling php is that it is using the result of $posttime1 / 60.0 and then, you randomly pass it a string it doesn't know what to do with. Try something like...

$posttime0 = $posttime1 / 60 . " minutes";


06-17-2006, 12:25 PM
or wrap your calculations in brackets.

06-17-2006, 05:40 PM
Awesome! Thanks a lot, that fixed it perfectly.