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 8 of 8
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Unhappy syntax error, unexpected ','

    Can someone help please and explain what I am doing wrong?


    PHP Code:
    $month=date("F",strtotime($dateStart));

    if(
    $month == "March"){
    if(
    $dateStart == strtotime($month),'last sunday of this month'){
        
    $GMT "+01"
    }



  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Having reformatted your code to that which is in the coding styles link in my sig, it's immediately obvious whats gone wrong - look:

    PHP Code:
    <?
    $month
    =date("F",strtotime($dateStart));//Ok

    if($month == "March")//Ok
       
    {
       if(
    $dateStart == strtotime($month),'last sunday of this month')//Not Ok *
          
    {
          
    $GMT "+01"//No semicolon ;
          
    }

       } 
    ?>
    *This line will not work. You're converting a string to a timestamp and then closing the function whilst outside of the function trying to use 'last sunday of..' and then include that mix into an IF comparison.

    I think what you were trying to achieve is this:
    PHP Code:
    if($dateStart == strtotime($month,'last sunday of this month')) 
    This doesn't work either. If you look at strtotime in the php manual you will see that you can only use a relative time string for the first parameter not the second which expects a timestamp.

    You need to take another look at the manual and rewrite your code.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    jarv (05-24-2011)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    That's some crazy indenting, tango.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Ah, but its much easier to understand all the code, find $end errors etc

    You should try it!
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    No, thanks. I prefer this format:
    PHP Code:
    <? 
    $month 
    date("F",strtotime($dateStart));//Ok 

    if($month == "March")//Ok 
    {
        if(
    $dateStart == strtotime($month),'last sunday of this month')//Not Ok * 
        

            
    $GMT "+01"//No semicolon ; 
        
    }
    }  
    ?>
    That's much easier to read to me.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    In my mind thats pretty much the same thing - the { and } are on their own lines instead of the { being at the end of the opening line.

    The only difference is that i found it easier to have the opening lines indentation normal and then the actual block of code indented as it may or may not run with the main code unlike the opening line (the if statement) which will always run.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by tangoforce View Post
    In my mind thats pretty much the same thing - the { and } are on their own lines instead of the { being at the end of the opening line.
    I'm with Inigo' on this one. Your layout is better than some, but the layout example he posted is by far the easiest to follow when you're scanning through lots of code. There's no guessing as to which follows what at all, which is why I use the generally same method as him.

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Hi Matt

    It's odd because the complete opposite is true at sitepoint - where they all prefer the opening { at the end of the same line (whoever thought that would work?) and the the closing brace on its own line at the far left (even with others above and below it). I never liked that and found it very annoying to debug and fix $end errors etc.

    Very strange, this forum actually seems to have far superior programmers and sitepoint seems to be the glossy well publicised site yet they do things so weirdly..
    Last edited by tangoforce; 05-25-2011 at 02:26 PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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