0
0
PHPprogramming~5 mins

Substring extraction in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Astrcut()
Bsubstring()
Cextract()
Dsubstr()
What does substr('abcdef', 2, 3) return?
A'cde'
B'bcd'
C'def'
D'abc'
If the start index is negative in substr(), what happens?
AReturns empty string
BStarts from the beginning
CStarts from the end backwards
DThrows an error
How to get substring from index 4 to the end in PHP?
Asubstr($str, 4)
Bsubstr($str, 0, 4)
Csubstr($str, -4)
Dsubstr($str, 4, 0)
What does substr('Hello', 1, 10) return?
A'Hello'
B'ello'
C'H'
DEmpty string
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.