Some Common/Useful Functions


PHP getcwd() Function +

The getchwd() function returns the current working directory.

Syntax:

getcwd();

echo getcwd()

The output will be :
/home/php

PHP dir() Function +

The dir() function returns an instance of the Directory class. This function is used to read a directory, which includes the following:

The given directory is opened

The two properties handle and path of dir() are available

Both handle and path properties have three methods: read(), rewind(), and close()

Syntax:

dir(directory,context);

$d = dir(getcwd());  // for current directory

echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";

while (($file = $d->read()) !== false){ 
  echo "filename: " . $file . "<br>"; 
} 
$d->close();

-----------------------------------------
$d = dir("oop"); // for oop directory

echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";

while (($file = $d->read()) !== false){ 
  echo "filename: " . $file . "<br>"; 
} 
$d->close(); 

The output will be:

Handle: Resource id #3
Path: oop
filename: .
filename: ..
filename: oop.php
filename: oop2.php
filename: oop3.php
filename: oop4.php
filename: oop5.php
filename: _notes