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 trialGurveer Singh
11,367 Pointscan i get help with reading data from php file?
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.
<?php
//add code here
$files = scandir('example');
if (srtpos($files, 'fun') != false) {
echo '<h3> <h3>';
}
2 Answers
Jeffrey Howard
18,173 PointsHi! You are almost there, just a few important items that needs to be added and fixed in order to complete this task.
You need a foreach loop to properly list out the files in the $files array.
Add your if statement inside the foreach loop but first the comparison operator should be typed with a double equal sign. For example !== false.
Variable $file should be placed in between the H3 tags.
The final product should look like the code below:
//add code here
$files = scandir('example');
foreach ($files as $file) {
if (strpos($file, 'fun') !== false ) {
echo '<h3>' . $file . '</h3>';
}
}
Hope this helps! Good Luck and happy coding!
Gurveer Singh
11,367 PointsThankyou very much, Jeff