Which of the following prints ‘text/xml’?
-
print substr($text, strchr($text, ':'));
-
print substr($text, strchr($text, ':') 1);
-
print substr($text, strpos($text, ':') 1);
-
print substr($text, strpos($text, ':') 2);
D
Correct answer
Explanation
The string is assumed to be 'Content-Type: text/xml'. Option D uses strpos to find the colon at index 13, then adds 2, skipping the colon and space to start at 't'. The output would be 'text/xml'. Option C only adds 1 (starts with space). Option A uses strchr which returns the rest of the string.