Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.