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

Glen Rose
Glen Rose
7,108 Points

strtolower challenge wont be acceptet

Hi

I´m watching a video on PHP Filehandling, and there is a challenge that I cant get accepted.

This is the 3 task out of 3, and the task is to make the filenames which contains the word "fun" to lowercase and display it after the <h3> title.

I have written the code which is attached and it works, but I wont get accepted.

Does anyone know why?

index.php
<?php
$dir = "example";
$files = scandir($dir);

foreach($files as $file) {

    if (strpos($file, "fun")) {

      echo "<h3>" . $file . "</h3>";
      echo strtolower($file);

      }elseif (strpos($file, "fun") === 0){

       echo "<h3>" . $file . "</h3>";
       echo strtolower($file);
    }

}

1 Answer

Heidi Fryzell
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Heidi Fryzell
Front End Web Development Treehouse Moderator 24,537 Points

Hi Glen,

I don't have a lot of experience with PHP but I found some other answers in the community section. If you copy the instructions from the challenge/task you are stuck on into the search on the community page you can sometimes find previous questions/answers.

Your code passed the first 2 tasks but then wasn't passing the 3rd. It looks like it has something to do with the way you were trying to display the file's content. Your <h3> tag seemed to be working but the content underneath was not.

Also, you use an "if" and an "esleif" statement. The code I found that passes uses an "if" and an "else".

Here is some code that will pass the 3rd task.

<?php
$dir = "example";
$files = scandir($dir);

$files = scandir('example');
foreach($files as $file){
  if(strpos($file, 'fun') === false){
    //do nothing
  }else{
    echo "<h3>$file</h3>";
    echo strtolower(file_get_contents('example/'.$file));
  }
}

I hope this helps and sorry I can't explain the code a little bit better.

Happy coding!

Glen Rose
Glen Rose
7,108 Points

Thanks a lot..... strange problem, but I wil try searching the community next time using some of the text. I tried searching the community, but couldnt find anything, but thats proberly because I didnt use the text from the task