Check out Scrivo

Do you want to try out Scrivo? Then here's a demo for you that does not just get your feet wet but lets you plunge right in.

Contact us

For more information, please contact us. We're happy to help you out!

Next Oct 10 Previous

Start 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.