© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_4

4. String

Mikael Olsson

(1)Hammarland, Finland

A string is a series of characters that can be stored in a variable. In PHP, strings are often delimited by single quotes.

$a = 'Hello';

String Concatenation

PHP has two string operators. The dot symbol is known as the concatenation operator(.). It combines two strings into one. It also has an accompanying assignment operator (.=), which appends the right-hand string to the left-hand string variable.

$b = $a . ' World'; // Hello World$a .= ' World';     // Hello World

Delimiting Strings

PHP strings can be delimited in four different ways. There are two common notations: double quote (" ") and single quote (

Get PHP 7 Quick Scripting Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.