0
0
PHPprogramming~5 mins

String length and counting in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What PHP function is used to find the length of a string?
The strlen() function returns the number of characters in a string.
Click to reveal answer
beginner
How does strlen() count characters in a string?
strlen() counts all characters including spaces, punctuation, and special characters.
Click to reveal answer
beginner
What will strlen('Hello World') return?
It returns 11 because there are 11 characters including the space.
Click to reveal answer
intermediate
How can you count how many times a specific character appears in a string in PHP?
Use the substr_count() function to count occurrences of a substring or character.
Click to reveal answer
beginner
What does substr_count('banana', 'a') return?
It returns 3 because the letter 'a' appears three times in 'banana'.
Click to reveal answer
Which PHP function returns the length of a string?
Astr_length()
Bcount()
Csubstr_count()
Dstrlen()
What will strlen('Hi!') return?
A2
B3
C4
D1
Which function counts how many times a substring appears in a string?
Asubstr_count()
Bstr_replace()
Cstrpos()
Dstrlen()
What does substr_count('apple', 'p') return?
A1
B3
C2
D0
Does strlen() count spaces in a string?
AYes
BNo
COnly if spaces are at the start
DOnly if spaces are at the end
Explain how to find the length of a string in PHP and what characters are counted.
Think about the function that returns the number of characters.
You got /3 concepts.
    Describe how to count how many times a specific letter appears in a string using PHP.
    There is a function that counts substrings inside strings.
    You got /3 concepts.