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 File Handling with PHP Basic File Handling Reading Files

Brian Thomas
Brian Thomas
10,688 Points

How do I write the code so it returns all the files starting with 'fun'?

strpos is stored in $start and is being used to test if it's FALSE. If it isn't echo the substr of $file using the int returned by strpos

index.php
<?php
//add code here
$files = scandir("example");
foreach($files as $file){
$start = strpos($file, 'fun');
if ($start != FALSE){
  echo substr($file, $start, 3).'</br>';
}
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

You're close, but there are a few issues:

  • the comparison should be type-sensitive to recognize the difference between 0 and FALSE
  • the outputs should be the the name of the file surrounded by H3 tags (not ended with "br")
  • the instructions ask for the entire file name to be displayed (not just a substring)