Skip to content

Chapter 11 of 38

Strings and Text Handling

Manipulate byte strings, multibyte text, interpolation, formatting, and search.

38 minutes 10 quick checksBy Subha Prasad
Lesson 11 of 38Course navigation

Lesson content

Read, practise, then check your understanding

PHP strings are byte sequences. Single quotes perform minimal escaping; double quotes and heredoc interpolate. Use mbstring or Intl when characters, locale, or Unicode semantics matter.

Practical example

<?php
$name = trim($input);
$message = sprintf('Hello, %s', $name);
$contains = str_contains($message, 'Hello');
$length = mb_strlen($message, 'UTF-8');

strlen counts bytes. Search, replacement, splitting, joining, and formatting do not escape output. HTML, URLs, headers, SQL, shells, and JSON each require their own contextual APIs. Normalize external encoding at boundaries.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes single-quoted string?
Which PHP term matches this description: A string with minimal escaping and no variable interpolation.
Which statement best describes double-quoted string?
Which PHP term matches this description: A string supporting escapes and variable interpolation.
Which statement best describes heredoc?
Which PHP term matches this description: Multiline string syntax with double-quoted-like interpolation.
Which statement best describes mbstring?
Which PHP term matches this description: An extension providing encoding-aware multibyte string operations.
Which statement best describes sprintf?
Which PHP term matches this description: Formatted string construction using placeholders.

0 of 10 checks passed

Your progress is saved on this device.