Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Parse error message?

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #43982
    matt_sanford
    Participant

    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:

    $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,

    #131134
    pixelgrid
    Participant

    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

    #131135
    matt_sanford
    Participant

    Sweet! thanks a lot! @pixelgrid

    #131137
    __
    Participant

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

    $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
    ;

    #131139
    matt_sanford
    Participant

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

    #131150
    __
    Participant

    you’re welcome.

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

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

    #131151
    CrocoDillon
    Participant

    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.
    #131183
    __
    Participant

    > 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.

    #131209
    CrocoDillon
    Participant

    Good to know, thanks :)

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Back End’ is closed to new topics and replies.