Wednesday, March 19, 2014

Given

$email = ‘bob@example.com’;

which code block will output example.com?

A. print substr($email, -1 * strrpos($email, ‘@’));

B. print substr($email, strrpos($email, ‘@’));

C. print substr($email, strpos($email, ‘@’) + 1);

D. print strstr($email, ‘@’);


Answer C is correct. strpos() identifies the position of the @ character in the

string.To capture only the domain part of the address, you must advance one place

to the first character after the @.

No comments:

Post a Comment