PHP: A greeting card

The first program every learner writes: say hello to a person whose name comes from the input.

What to build

A program that greets a person.

Requirements

  • Read one line with the name (it may contain spaces).
  • Print Hello, NAME! on the first line and Welcome to PHP. on the second.

Input

One line: the name.

Output

Two lines.

Constraints

The name has 1 to 40 characters.

Example

Input:

Ada

Output:

Hello, Ada!
Welcome to PHP.

Why it works

Double-quoted text fills in the variable, and trim removes the line break so the name is clean.

Examples

Example 1 · Input
Ada
Expected output
Hello, Ada!
Welcome to PHP.
Example 2 · Input
Grace Hopper
Expected output
Hello, Grace Hopper!
Welcome to PHP.

Hints

Hint 1

Read the line with trim(fgets(STDIN)).

Hint 2

Put the name inside double quotes: "Hello, $name!\n".

Solution

Show one correct solution (try it yourself first)
<?php
$name = trim(fgets(STDIN));
echo "Hello, $name!\n";
echo "Welcome to PHP.\n";

▶ Open this solution in the compiler

Lesson: Your first PHP program →