All lessons

Working with Text

7 min · PHP

Join strings, measure them, and embed variables.

PHP · Working with Text0/5 cleared

Enemy 1 of 5

Strings and concatenation

A string is just a run of text, and PHP lets you write one with either double quotes ("...") or single quotes ('...'). The two look similar but behave differently, which trips up almost every beginner at least once — more on that below.

To combine two strings into one, PHP uses the . operator, called concatenation. It doesn't add a space for you automatically, so "Hello" . "World" produces "HelloWorld" with no gap — if you want a space, you have to include it yourself, either as its own string ("Hello" . " " . "World") or baked into one of the pieces, as the example below does.

You
Packet Wolf

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, Ada