PHP String Handling Quiz
A 30-question quiz on PHP string handling, covering interpolation, encoding, concatenation, formatting, searching, and multibyte safety so everyday text processing stays predictable.
Question 1
Why do code reviews ask engineers to explain whether a string should use single or double quotes when no interpolation is needed?
Question 2
A teammate tests interpolation. What does this snippet print?
<?php
$user = 'Nova';
echo "Hello $user";
echo ' | Hello $user';
?>Question 3
During localization planning, why is mb_strlen preferred over strlen for user-facing names?
Question 4
What does this snippet log?
<?php
echo strlen('café');
?>Question 5
A helper escapes HTML before logging. What prints?
<?php
$input = '<strong>Sale</strong>';
echo htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
?>Question 6
Why do architecture guidelines warn against concatenating user input into SQL strings for debugging even when the SQL is not executed?
Question 7
A template uses heredoc to format copy. What appears?
<?php
$plan = 'Pro';
$message = <<<TEXT
Plan: $plan
Thank you!
TEXT;
echo $message;
?>Question 8
When formatting currency strings for UI, why do teams prefer number_format over manual concatenation of symbols?
Question 9
What does this trimming helper print?
<?php
$sku = " item-24 ";
echo trim($sku);
?>Question 10
Why should log messages use sprintf placeholders instead of concatenating user input directly?
Question 11
What does this sprintf call output?
<?php
$amount = 12.5;
echo sprintf('%.02f USD', $amount);
?>Question 12
Why is json_encode with JSON_UNESCAPED_UNICODE useful when sending localized strings to clients?
Question 13
A snippet removes prefix text. What prints?
<?php
$value = 'order:123';
echo substr($value, 6);
?>Question 14
Why do product teams prefer str_contains over strpos !== false when scanning for keywords in PHP 8+ codebases?
Question 15
What does this substring check echo?
<?php
echo str_contains('production', 'duct') ? 'found' : 'missing';
?>Question 16
When sanitizing filenames, why is preg_replace with a whitelist pattern safer than stripping disallowed characters one by one?
Question 17
A cleanup filter keeps safe characters. What prints?
<?php
$raw = 'report_2025?.pdf';
echo preg_replace('/[^A-Za-z0-9_.-]/', '', $raw);
?>Question 18
Why do review checklists ask whether string replacements should be case-insensitive, especially for user-entered keywords?
Question 19
What does this str_ireplace snippet echo?
<?php
echo str_ireplace('sale', 'deal', 'SALE starts now!');
?>Question 20
When documenting APIs, why should examples show whether strings include trailing newline characters?
Question 21
A snippet normalizes line endings. What prints?
<?php
$text = "Line1
Line2";
echo str_replace(["
", "
"], "
", $text);
?>Question 22
Why do teams log the encoding (UTF-8 vs ISO-8859-1) when debugging garbled characters?
Question 23
What does this iconv snippet output?
<?php
$latin = iconv('ISO-8859-1', 'UTF-8', "Éclair");
echo $latin;
?>Question 24
Why is htmlentities often reserved for content that needs full entity encoding rather than minimal escaping?
Question 25
What does this htmlentities call echo?
<?php
echo htmlentities('"Paris" & "Lyon"', ENT_QUOTES, 'UTF-8');
?>Question 26
Why do mentoring guides encourage using sprintf rather than concatenation when building sentences with multiple variables?
Question 27
What does this formatted sentence output?
<?php
$city = 'Jakarta';
$temp = 31;
echo sprintf('%s is %d°C today.', $city, $temp);
?>Question 28
Why is strtoupper inappropriate for locale-aware case conversions such as Turkish dotted/dotless I?
Question 29
What does this mb_strtoupper snippet echo?
<?php
echo mb_strtoupper('istanbul', 'tr_TR');
?>Question 30
Why do documentation templates remind developers to normalize whitespace before comparing multiline strings in tests?
