World Wide Web Programming

Some hints. • You can use a table that will hold the elements and their type. • You can sort the table with your own function. • Remember to do a chdir before ...
149KB taille 2 téléchargements 379 vues
World Wide Web Programming 7 – Introduction to PHP Part III

Information on files ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹

basename($path) clearstatcache() diskfreespace($dir) file_exists(“file”) fileatime(“file”) filectime(“file”) filegroup(“file”) fileinode(“file”) filemtime(“file”) fileowner(“file”) fileperms(“file”) filesize(“file”)

‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹

filetype(“file”) is_dir(“file”) is_executable is_file is_link is_readable is_writeable linkinfo($link) lstat(“file”) readlink($lnk) stat()

Using directories ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹ ‹

chdir($dir) closedir($dir) dir($dir) dirname($path) mkdir(“path”,$mode) opendir($dir) readdir($dir) rewinddir($dir) rmdir($dir)

Manipulating Strings ‹

Few of the interesting functions • • •

chop($str) ltrim($str) str_replace($strs,$stre,$str) ‹

Replaces all the $strs in $str by $stre

• trim($str) == chop(ltrim($str)) • AddSlashes and StripSlashes add or take out the \ in front of special character ‹

When saving a string it may be preferable to add the slashes, but when printing it, take them off

Changing string strrev ‹ strtolower ‹ strtoupper ‹ ucfirst ‹ ucwords ‹ ord(“A”) returns the ASCII value ‹ $arr=explode($sep,$str) ‹ $str=implode($sep,$arr) ‹

Finding and comparing $res=strcmp($str1, $str2) ‹ strcasecmp ‹ strnatcmp ‹ strnatcasecmp ‹ $res=strpos($str,$strr,$offset) ‹ $res=strrpos($str,$char) ‹ $str1=substr($str,$start,$length) ‹

Editing characters and strings chr ‹ echo ‹ print ‹ printf(“%s%s%s”,$a,$b,$c); ‹

• b – integer / c – ASCII / d – decimal / f – floating point / o – octal / s – string / x or X – hexadecimal

$res=sprintf(…) ‹ flush() ‹

Manipulating URLs get_meta_tags ‹ nl2br ‹ rawurlencode ‹ rawurldecode ‹ strip_tags ‹

Some PHP information functions $val=getenv($varname) ‹ $val=get_cfg_var($varname) ‹ $user=get_current_user() ‹ $val=getmypid() ‹ $val=getmyuid() ‹ phpinfo() ‹ $val=phpversion(); ‹

Some important vars ‹



HOMEWORK 3A ‹

Create a PHP script that will do the following

• Show the path of any folder • Show all the folders and then all the files of the folder • You will add a link to every file you will find

‹

Some hints

• You can use a table that will hold the elements and their type • You can sort the table with your own function • Remember to do a chdir before opening a folder

HOMEWORK 3B ‹

‹ ‹ ‹ ‹ ‹

‹

Create a script that will open a the following file: http://cs465.free.fr/files/hw3b.html Capture all the meta information of the file Take all the tags off Get all the words of the file Count how many of each word exist Output a list of the existing words with the number of occurrences Give all the META information you can