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 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
216,133 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)