25. Working with Strings: Concatenation and Length
Strings are sequences of characters and are one of the most common data types you will handle in PHP.
String Delimiters
PHP strings can be enclosed in single quotes ('') or double quotes ("").
- Single Quotes: Literal interpretation. Variables are not expanded.
- Double Quotes: Supports variable interpolation (embedding variables directly).
php
"; echo "Hello, $name"; // Output: Hello, Bob (Interpolated) ?>Concatenation
The period (.) operator is used to join strings together.
php
" . $message; ?>String Length
Use the strlen() function to determine the length (number of bytes) of a string.
php
Length of text: " . $length; // Output: 13 ?>Note: For strings containing multi-byte characters (like emojis or non-Latin scripts), you should use mb_strlen() (Multi-Byte String functions) for accurate character counts.