Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Adding Search: Model > Using stripos: Starts with R > task 2 of 2

After completing task 1 of 2, the task simply asks you to change two variables to two defined values to test the code. When I do this, it says;

Oops! It looks like Task 1 is no longer passing...

4 Answers

Hi Randy. Sure.

<?php

$var1 = "Rocky Road";
$var2 = "Raspberry";
$initial = "R";

if (strpos($var1,$initial) == 1 && strpos($var2,$initial) == 1) {

    echo $var1 . " and " . $var2 . " both start with " . $initial . ".";

} else {

    echo "Either " . $var1 . " or " . $var2 . " doesn't start with " . $initial . "; maybe neither of them do.";

}

?>
Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

It looks like you made the wrong change in step 1 to get it to pass. You need to use the stripos function, but something else needs to change. Why would it think that broccoli starts with R? What number does the stripos function return if a word does start with the letter specified?

Hint: Does broccoli have an R anywhere in it? Not at the beginning but somewhere else?

AH!

A forehead slap moment....

You had it set as

if (stripos($var1,$initial) == 1 && stripos($var2,$initial) == 1) {

so replacing == 1 with == 0, it is now checking that the returned number from the stripos function matches the first character as apposed to the second character.

Thanks for your help. Look forward to your next installments Randy! learned more in the past 7 days then I have in 7 months.