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

Danny Massa
Danny Massa
27,856 Points

If the filename contains the string "fun", display the name of the file surrounded by H3 tags.

File Handing with PHP

Challenge Task 2 of 3

If the filename contains the string "fun", display the name of the file surrounded by H3 tags. HINT: strpos will return 0 if the result is found at the beginning of the file. Returns FALSE if the needle was not found.

I'm not sure why my code is not passing, can someone please help?

error: Bummer! I do not see all the required content.

<?php
//add code here
$files = scandir("example");

foreach ($files as $file) {
  if (substr($file, 0, 1) == 'f') {
    echo '<h3>' . $file . '</h3>';
  } 
}

2 Answers

please use below lines for getting rid of it

<?php $files = scandir('example'); foreach($files as $file) { if (strpos($file,"fun",0) !== false) { echo '<h3>' . $file . '</h3>'; }else{ echo $file; } } ?>