Below, I have prepared a list of 10 practical challenges to train your syntax, logic, and HTML integration in PHP. Try to solve all of them without copying and pasting! Open your text editor, start your XAMPP server, and let's get to work.
The Exercise List: PHP Output & Syntax
Create a PHP script that outputs the following phrase to an HTML document: "The first program we write, we never forget!".
Develop a script that prints your full name on the first line, your address on the second line, and your ZIP code and phone number on the third line. Use HTML tags inside your PHP strings to organize the line breaks.
Write a script that outputs the chorus of your favorite song to the screen.
(Hint: You will need multiple `<br />` tags to separate the verses properly!)
Implement a PHP page that prints a funny or special message. Take a screenshot of the browser output and send it to a friend saying you built a "creative virus" that infected your localhost!
Create a program that displays a bulleted list (using HTML `<ul>` and `<li>` tags inside your `echo`) of what web apps or systems you intend to build once you master PHP.
Write a program that produces the following geometric figure in the browser using uppercase 'X':
XXXXX
X X
X X
X X
XXXXX
You were hired by a school. As your first task, develop a script that generates exactly the following text-based table:
STUDENT GRADE
========= =====
ALICE 9.0
MARIO TEN
SERGIO 4.5
SHIRLEY 7.0
Create a script to print the letter "P" (for PHP Progressive) on the screen using characters. Use the letter "L" below as an inspiration for the format:
L
L
L
LLLLL
Simulate a terminal-based customer registration menu with the following visual structure:
Customer Management System
0 - Exit
1 - Create
2 - Update
3 - Delete
4 - Read
Select an option: _
Implement a program that draws a "pine tree" on the screen. Try using different characters (like `*`, `O`, `+`) to simulate ornaments on the tree!
X
XXX
XXXXX
XXXXXXX
XXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXXXXX
XX
XX
XXXX
💡 Master Tips for ASCII Art:
- To keep your drawings (like the pine tree and the table) perfectly aligned in the browser, wrap your PHP output inside an HTML
<pre>(Preformatted Text) tag. - Practice using both single quotes (
') and double quotes (") to feel the difference. - Never forget the mandatory semicolon (
;) at the end of each statement!
I'm waiting for your source code in the comments! Which exercise was the most challenging for you?
What's Next? Variables and Data Types!
Printing hardcoded text is fun, but real applications need to store, manipulate, and process dynamic information. In our next tutorial, you will learn the most fundamental concept in programming: Variables. This is where your code truly starts to "think."
Go to the Next Lesson in the Syllabus →
Nenhum comentário:
Postar um comentário