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 trialMicheal Russell
Courses Plus Student 1,312 PointsBummer! I do not see the h3 tags. I cannot get passed this error. What am I missing in this course
The h3 tags are there the code works why am I getting this error. What lesson was it in.
<?php
//add code here
$files = scandir('example');
$dir = 'example' ;
if ( $dh = opendir ( $dir )) {
while (( $file = readdir ( $dh )) !== false ) {
if ( substr ( $file , 0, 3) !== 'fun' ) {
//do something with $file
echo $file;
} else {
echo "<h3>filename: " . $file . "</h3>";
}
}
closedir ( $dh );
}
?>
3 Answers
Umesh Ravji
42,386 PointsHi Micheal
- You have to check for the value of
fun
within the file name, not just at the start. Use thestrpos()
function for this. - You don't need the else on your condition. If the string
fun
can be found within any file, perform theecho()
statement, there is no else. - Only print out what is required. Adding extra text, such as
filename:
between the tags, can throw the engine off and give you an incorrect answer.
Just as a note, in the first step you obtained an array of all the files within the example
directory, so you don't the while loop to read the contents of the directory again. It's much simpler to use the $files
array in a foreach
loop.
$files = scandir('example');
foreach ($files as $file) {
// do something with $file
}
Micheal Russell
Courses Plus Student 1,312 Pointsumesh you are the greatest I am down for the night but in the am i will apply your reply thank you.
Umesh Ravji
42,386 PointsDid it not work? The downvote?
Micheal Russell
Courses Plus Student 1,312 PointsI believe you asked what lesson it was. it is File Handling with PHP , step 4 Reading Files
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsMicheal Russell Umesh Ravji
I am confused as to why this response was originally 'downvoted'?? (Which I have removed and have marked as Best Answer).
The answer is clear and provides all the necessary information to work through the errors in the code from the original post. In fact, in my opinion, this is a very well thought out and explained answer. Thank-you Umesh.
Jason ~~ Treehouse Community Moderator