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

struck on ccodechallenge

I have this block of code that isn’t working correctly, but I can’t figure out the problem. It says that the name of my favorite flavor of ice cream ('Cookie Dough') does not contain the search term 'cookie', but it does. Can you take a look? Can you change it so that it checks that the value in $search_term is found within $flavor correctly?

5 Answers

Richard Duncan
Richard Duncan
5,568 Points

stripos expects 2 parameters seperated by a comma , not a period .. So if you simply replace the period with a comma it will output:

Randy's favorite flavor of ice cream contains the search term 'vanilla'.

<?php

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

if (stripos($search_term.$flavor) !== true) {

    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 . "'.";

}

?>

I am Struck on this task please help...TASK:2

Brian Enos
Brian Enos
10,468 Points
<?php
$flavor = "Cookie Dough";
$search_term = "vanilla";

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 . "'.";

}
?>

thank you so much Richard Duncan I completed the task....

Richard Duncan
Richard Duncan
5,568 Points

No worries. You could mark my answer if you wanted :D

its k now i got the answer Richard

Richard Duncan
Richard Duncan
5,568 Points

I meant up vote or mark as best answer.

ya i did