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 Enhancing a Simple PHP Application Adding Search: Model Using strpos: Searching for Cookie

PHP Development Code Challenge

Must be overlooking something but can't figure it out.

$flavor = "Vanilla";
$search_term = "cookie";

if (stripos($flavor,$search_term) !== false) {

    echo "Randy's favorite flavor of ice cream contains the search term '" . $search_term . "'.";

} else {

    echo "Randy's favorite flavor of ice cream does NOT contain the search term '" . $search_term . "'.";

}

In the first case the stripos($flavor,$search_term) were switched.

If(stripos(the case insensitive string position) is not a false match to the object -> !== it should echo out the correct sentence, in this case the second statement.

What am I missing?

When I tried the above code it gave me the 2nd sentence as the answer so it seems to be working the way you describe

2 Answers

Logan R
Logan R
22,989 Points

You changed the wrong value, it wants you to change the search value, not the flavor.

$flavor = "Cookie Dough";
$search_term = "vanilla";

Good luck!

I was too focused on the logic that I forgot to read carefully it seems. Thanks!

Logan R
Logan R
22,989 Points

It's all good :) I've done it before too.