PHP Strings and Variables

illustration of string

In everyday conversation, we use the word data to refer to any sort of information. This information is often a list of numbers, like a company’s monthly expenses or statistics about an athlete’s performance. However, in programming, data means something very specific. It’s still information, but that information takes the form of a few specific types.

The PHP language has different ways of handling different types of data. Which actions the computer can perform and how the computer stores the data in memory will vary based on the type. In this lesson, we’ll be learning about the string data type.

Strings are words or pieces of text that the computer treats as a single item. A string is a sequence of characters. It can be any length and contain any letters, numbers, symbols, or spaces surrounded by quotation marks.

echo "My first string"; // Prints: My first string

It’s important to distinguish between strings and the rest of the code in a PHP program. Every part of a program is text, but strings are the parts we intend to keep as data—not as instructions to be executed by computer. In this lesson we’re going to focus on strings wrapped in double quotation marks (if you’re curious, you can check out the official PHP documentation to see other types of PHP strings).

In later lessons, we’ll be using PHP to create custom HTML documents enabling dynamic web pages. As we learn the basics, however, we’ll be writing simple PHP only programs that run in the terminal.

Let’s make some strings!



Let’s start with the classic. Use the echo keyword to print Hello, World!.

You should always end a PHP statement with a semicolon.

Folder Icon

Take this course for free

Already have an account?