Recall & Review
beginner
What PHP function is used to extract a part of a string?
The
substr() function is used to extract a substring from a string in PHP.Click to reveal answer
beginner
How do you extract the first 5 characters from a string
$text in PHP?Use
substr($text, 0, 5); where 0 is the start position and 5 is the length.Click to reveal answer
intermediate
What happens if the start position in
substr() is negative?A negative start means counting from the end of the string backwards.
Click to reveal answer
beginner
How to extract a substring from position 3 to the end of the string in PHP?
Use
substr($string, 3); to get substring from index 3 to the end.Click to reveal answer
beginner
What does
substr('Hello World', 6, 5) return?It returns
'World', starting at index 6 and taking 5 characters.Click to reveal answer
Which function extracts a substring in PHP?
✗ Incorrect
The correct function to extract substrings in PHP is
substr().What does
substr('abcdef', 2, 3) return?✗ Incorrect
Starting at index 2 ('c'), taking 3 characters gives 'cde'.
If the start index is negative in
substr(), what happens?✗ Incorrect
A negative start index counts from the end of the string backwards.
How to get substring from index 4 to the end in PHP?
✗ Incorrect
Using
substr($str, 4) extracts from index 4 to the end.What does
substr('Hello', 1, 10) return?✗ Incorrect
If length exceeds string end, it returns substring from start to end, here 'ello'.
Explain how to use the
substr() function in PHP to extract parts of a string.Think about start index and how length controls substring size.
You got /4 concepts.
Describe what happens when you use a negative start index in PHP's
substr().Imagine counting backwards from the string's last character.
You got /3 concepts.