Skip to content

Learn PHP in Seven Days

Spend about 20–30 minutes on a task each day. You will start with a single line of PHP and finish by adapting a small reading list that remembers its books between visits.

Open the browser example in Write and Run Your First PHP Script. Change the words in the quoted greeting and run the example. You are ready to continue when you see your new output.

Follow the PHP setup lesson for your operating system. Save your greeting in hello.php and run php hello.php in the terminal from the folder where you saved it. Compare the result with yesterday’s browser output.

Start a new file named books.php. Put your own titles in the array and run php books.php.

<?php
$books = ['Dune', 'Kindred', 'The Hobbit'];
foreach ($books as $book) {
echo $book, PHP_EOL;
}

Expect one title on each line. Add a fourth title and check that it appears. PHP arrays

Follow PHP for HTML and CSS developers to make a form that greets you. A working page reads Hello, Sam! after you submit Sam. Change the heading and button text to see which part of the page HTML controls.

In your greeting page, submit a value containing spaces around the name and check that trim() removes the extra spaces. Then submit A & B. The browser should display the ampersand, and the page source will show it escaped as &amp;. Point to the line that reads the input and the separate line that formats it for HTML. Handling form input

Follow the PHP and SQLite starter in a fresh folder. Add one or more of your own titles. Mark one as read. Stop and restart the local server, then confirm that the titles and read status are still there.

To see the change on a fresh list, add Dune first and Kindred second. The original query shows the newer title first. Open public/index.php in the reading list project and find the query containing ORDER BY id DESC. Change that part of the query to ORDER BY title COLLATE NOCASE, id DESC. Reload the list and verify that Dune appears before Kindred regardless of when you added them.

Add another title, mark it as read, and refresh the page. Check that the new book is in alphabetical order and its read status persists. Learn how the query works · Continue with PHP Basics