Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    T_CONSTANT_ENCAPSED_STRING error

    Hello.

    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:

    PHP Code:
        $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!

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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";

    ~Phil~

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    or wrap your calculations in brackets.

  • #4
    New Coder
    Join Date
    Jun 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome! Thanks a lot, that fixed it perfectly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •