Grow your CSS skills. Land your dream job.

Parse error message?

  • # April 9, 2013 at 10:45 am

    Hey guys, pretty new to php and as you have probably seen in prior posts, new to the web in general.

    I am working on trying to get a schedule together in php but for whatever reason it isn’t working. Here is what I have so far:

    < ?php
    $day = array(“Friday”, “Saturday”, “Sunday”);
    $hourAm = array(6, 7, 8, 9, 10, 11);
    $hourPm = array(12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);

    foreach ($hourAm as $hourA) {
    echo “

    ” . $hourA . “//It won’t show it, but I do have the html tags closed here.

    “;
    }

    unset($hourA);

    ?>

    I dont know what is going on but when i try to view this on my local server I get this : “Parse error: parse error, expecting `’,” or `’;” in /Users/matt/Sites/Summit13/Schedule/index.php on line 20″
    Any ideas?
    Cheers,

    # April 9, 2013 at 10:56 am

    change the quotes for class = “hour” from double to single or the outter ones from double to single.
    note that inside double quotes you can have the values of variables withour concatanating.

    so

    ''< td class='hour'> $hourA < td>''

    would work too

    # April 9, 2013 at 11:03 am

    Sweet! thanks a lot! @pixelgrid

    __
    # April 9, 2013 at 11:08 am

    Another option for HTML strings (especially larger ones) which I prefer is HEREDOC syntax.

    < ?php
    $html_string = < <

    Using HEREDOC Notation

    A “HEREDOC” starts with three less-than brackets,
    followed by an identifier of your choosing.
    I used [uppercase] “html”, but any text works.
    It ends with that same identifier (*all by itself*, on a new line!)
    and the closing semicolon.

    As you can see, both single- and double-quotes
    aren’t a problem inside a HEREDOC.
    You can also use $variables
    (or even {$arrays})
    but not functions() or CONSTANTS.
    HTML
    ;

    # April 9, 2013 at 11:51 am

    I don’t think I will be needing to use strings larger than 5 words but that is very helpful. @traq

    __
    # April 9, 2013 at 2:07 pm

    you’re welcome.

    More so than length, the determining factor for me is often:

    > *”do I need to use both single- **and** double-quotes?”*

    # April 9, 2013 at 3:20 pm

    You can always escape quotes when needed, for short strings that might be easier to read than heredoc syntax (where the terminating semicolon can be on the same line as the identifier btw).

    This `” “` would have worked.

    __
    # April 9, 2013 at 6:57 pm

    > the terminating semicolon can be on the same line as the identifier btw.

    yes (supposedly). On some systems/builds, it needs its own line. I’ve run into this only once (it was an Ubuntu desktop running php5.2); I never figured out why. I know it’s obscure, but putting the semicolon on its own line works **everywhere**, so I made a habit of it.

    # April 10, 2013 at 3:17 am

    Good to know, thanks :)

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".