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

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 25,178 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