Multiple choice php

Which of the following prints ‘text/xml’?

  1. print substr($text, strchr($text, ':'));
  2. print substr($text, strchr($text, ':') 1);
  3. print substr($text, strpos($text, ':') 1);
  4. print substr($text, strpos($text, ':') 2);
Reveal answer Fill a bubble to check yourself
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.