$Three3 Posted December 30, 2009 Share Posted December 30, 2009 Hey everyone, I have been reading a php book and following all of the examples in the book but I am stuck on this one line. I actually understand the hardest part of this script but not the simple part. Here is the code: <?php date_default_timezone_set('US/Central') ; //Scan directories $searchDirectory = '.' ; $directoryScan = scandir($searchDirectory) ; //Create a list of directories first echo "<h2>Directories</h2>" ; echo "<ul>" ; //Access the contents of the directory foreach ($directoryScan as $contents) { if ((is_dir($contents)) AND (substr($contents , 0 , 1) != '.')) { echo "<li>$contents</li>" ; } } echo "</ul>" ; //Create Files header echo "<hr /><h1>Files</h1>" ; //Create Table echo '<table cellpadding="2" cellspacing="10" align="left">' ; //Create Files Row echo "<tr> <td><b><u>Name</u></b></td> <td><b><u>Size</u></b></td> <td><b><u>Last Modified</u></b></td> <td><b><u>File Permissions</u></b></td> <td><b><u>File Owner</u></b></td> <td><b><u>File Last Accessed</u></b></td> </tr>" ; //Access the files in the directory foreach ($directoryScan as $contents) { if ((is_file($contents)) AND (substr($contents, 0 , 1) != '.')) { //Create File Size & Last Mod date $fs = filesize($contents) ; $lm = date('F j, Y' , filemtime($contents)) ; $fp = fileperms($contents) ; $fo = fileowner($contents) ; $fla = date('F j, Y' , fileatime($contents)) ; //Print Out Data echo "<tr> <td>$contents</td> <td>$fs</td> <td>$lm</td> <td>$fp</td> <td>$fo</td> <td>$fla</td> </tr>" ; } } echo "</table>" ; ?> What is confusing me is this line: if ((is_dir($contents)) AND (substr($contents , 0 , 1) != '.')) { I understand that whole line but what I do not understand is the part with the '.' period. What does this mean? Thanks in advance for the help. Link to comment https://forums.phpfreaks.com/topic/186741-need-just-a-little-bit-of-help-with-this-line-of-code/ Share on other sites More sharing options...
salathe Posted December 30, 2009 Share Posted December 30, 2009 Well $contents is the name of a file or folder within the directory. The part of the if which is substr($contents, 0, 1) != '.' is simply saying if the first character in $contents is not a dot/period. The '.' is just a PHP string containing a dot, nothing magical or special. Link to comment https://forums.phpfreaks.com/topic/186741-need-just-a-little-bit-of-help-with-this-line-of-code/#findComment-986148 Share on other sites More sharing options...
$Three3 Posted December 30, 2009 Author Share Posted December 30, 2009 Well $contents is the name of a file or folder within the directory. The part of the if which is substr($contents, 0, 1) != '.' is simply saying if the first character in $contents is not a dot/period. The '.' is just a PHP string containing a dot, nothing magical or special. Hey thanks for the reply. Okay I understand that now but what I do not understand is why you would want to make sure that variable $contents is not equal to a dot/period? Thanks again man Link to comment https://forums.phpfreaks.com/topic/186741-need-just-a-little-bit-of-help-with-this-line-of-code/#findComment-986152 Share on other sites More sharing options...
salathe Posted December 30, 2009 Share Posted December 30, 2009 The contents of the folder will have special traversal "folders" called . and .. (for current and parent folders respectively) and also "hidden" files are commonly a prefixed with a dot. Take a look at the scandir manual page. Link to comment https://forums.phpfreaks.com/topic/186741-need-just-a-little-bit-of-help-with-this-line-of-code/#findComment-986154 Share on other sites More sharing options...
$Three3 Posted December 30, 2009 Author Share Posted December 30, 2009 The contents of the folder will have special traversal "folders" called . and .. (for current and parent folders respectively) and also "hidden" files are commonly a prefixed with a dot. Take a look at the scandir manual page. Awesome. I understand now. Thanks a lot for that link and for your time and help. Appreciate it Link to comment https://forums.phpfreaks.com/topic/186741-need-just-a-little-bit-of-help-with-this-line-of-code/#findComment-986155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.