- This topic is empty.
-
AuthorPosts
-
April 9, 2013 at 10:45 am #43982
matt_sanford
ParticipantHey 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,April 9, 2013 at 10:56 am #131134pixelgrid
Participantchange 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 #131135matt_sanford
ParticipantSweet! thanks a lot! @pixelgrid
April 9, 2013 at 11:08 am #131137__
ParticipantAnother 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
;April 9, 2013 at 11:51 am #131139matt_sanford
ParticipantI 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 #131150__
Participantyou’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 #131151CrocoDillon
ParticipantYou 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 #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.
April 10, 2013 at 3:17 am #131209CrocoDillon
ParticipantGood to know, thanks :)
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.