Chapter 1 of the Learn PHP 8 from scratch track

Today's front page

6 exercises · 600 XP · about 1 h 45 min · free first chapter

This chapter works on: echoVariableStringNumberConcatenationdate()ArrayAssociative arrayforeachifelseBooleanComparisonString functionsmb_strlen()mb_substr()mb_strtoupper()FunctionTypereturnhtmlspecialchars()

The chapter's exercises

  1. Hello Saint-Glinglin

    Exercise 1 · 100 XP · 5 objectives checked by tests

    In Saint-Glinglin, the news has always traveled by mailbox. Madame Lou, the postwoman and editor-in-chief of the village gazette, has decided to put it online. She has even found a good old-fashioned stylesheet. All that's missing is you, and a few lines of PHP.

    echoVariableString

  2. The date in the masthead

    Exercise 2 · 100 XP · 5 objectives checked by tests

    The gazette has a title, but Madame Lou is a stickler for tradition: every issue carries its issue number, today's date and its price. “Fifty cents, same as in 1987.”

    VariableNumberConcatenationdate()

  3. Today's articles

    Exercise 3 · 100 XP · 4 objectives checked by tests

    Madame Lou has gathered today's news. Gaston, the village constable, wrote two articles, and she wrote one herself. A page per story, by hand? No way: PHP knows how to repeat itself.

    ArrayAssociative arrayforeach

  4. The top story

    Exercise 4 · 100 XP · 4 objectives checked by tests

    Not all news is created equal: the pumpkin festival is the event of the year. Madame Lou has marked it with 'une' => true (une means front page). As for the article about the mayor's cat, Gaston has taken his name off it: he'd rather not fall out with the mayor.

    ifelseBooleanComparison

  5. The standfirst

    Exercise 5 · 100 XP · 4 objectives checked by tests

    The articles now have a rubrique (section) and a texte (text). But on the front page, Madame Lou only wants the standfirst, those few words that make you want to read on. And she likes her sections in capitals, “like in the real newspapers”.

    String functionsmb_strlen()mb_substr()mb_strtoupper()

  6. One function per article

    Exercise 6 · 100 XP · 5 objectives checked by tests

    The loop has grown: banner, section, author, standfirst… And Léo, the mayor's grandson, has promised to slip a <script> tag into a title “just to see”. Time to tidy this code into a function, and to make it careful.

    FunctionTypereturnhtmlspecialchars()