Next Oct 10 PreviousStart from the end or the beginning?
What will be the output of the following program:
<?php
echo stripos("Experience the power of PHP", "p", -2);
?>
A: 2
B: 15
C: 24
D: 26
E: nothing
Answer
Some PHP string functions such as substr()
can accept negative offsets to indicate that you want to start your search from the end of the string. However this is not the case for strpos()
and stripos()
. When a negative offset is given these functions will fail and return false. So answer E is correct: nothing (or a warning) will be printed.