Use of the phpstr_replace function when the parameter is an array

Source: Internet
Author: User
Tags filegroup symlink
Phpstr_replace: This section describes the system functions related to file operations in PHP. these functions are also very important, the following examples are still common examples.

Basename-part of the file name in the returned path

Dirname-directory part of the returned path

String basename (string $ path [, string $ suffix])

String dirname (string $ path)

Sample code:

// PHP blog https://www.php1.cn

$ Path = "/home/httpd/www. phpcn/index. php ";

Echo basename ($ path );

Echo basename ($ path, '. php ');

Echo basename ($ path, '. xxx ');

Echo dirname ($ path );

?>

// Result:

Index. php

Index

Index. php

/Home/httpd/www.phpfensi.com

Note: If the file name ends with a correct suffix file, this part will be removed.

Chgrp-change the group to which the file belongs

Chown-change the file owner

Chmod-change file mode

Bool chmod (string $ filename, int $ mode)

Sample Code: chmod ('/home/phpha.txt', 0755 );

Copy:

If (copy ('index. php', 'index. php. bak ')){

Echo 'copy success ';

}

The index. php. bak file is saved in the current directory.

Delete-see unlink or unset

Unlink-delete an object

The code is as follows:

If (unlink ('index. php. bak ')){

Echo 'unlink success ';

}

?>

Index. php. bak deleted

Disk_free_space-return the available space in the directory

Disk_total_space-returns the total disk size of a directory

Diskfreespace-disk_free_space alias

The code is as follows:

// In Windows:

Echo disk_free_space ("C :"),'
';

Echo disk_total_space ("C :");

?>

// Result: the number of bytes is returned.

17433419776

32218386432

Fopen-open a file or URL

Fgets-read a row from the file pointer

Feof-test whether the file pointer is at the end of the file

Fread-read files (which can be safely used for binary files)

Fwrite-write a file (which can be safely used for binary files)

Fclose-close an opened file pointer

The code is as follows:

$ Fp = fopen('hello.txt ', 'r'); // open a file

$ N = 1;

While (! Feof ($ fp )){

Echo $ n, '-', fgets ($ fp ),'
'; // Read and output a row

$ N ++;

}

Fclose ($ fp); // close the file

?>

// Output:

1-Welcome to my blog:

2-http://www.phpfensi.com

Fgetc-read characters from the file pointer

Fgetcsv-read a row from the file pointer and parse the CSV field

Fgetss-read a row from the file pointer and filter out the HTML tag

Fputcsv-format rows as CSV and write file pointers

Fputs-fwrite alias

The code is as follows:

$ Fp = fopen('hello.txt ', 'r ');

While (false! ==( $ Char = fgetc ($ fp ))){

Echo $ char ,'-';

}

?>

// Output:

W-e-l-c-o-m-e--t-o--m-y-B-l-o-g -: ---h-t-p-:-/-B-l-o-g -. -p-h--. -c-o-m-

File_exists-check whether a file or directory exists. the code is as follows:

If(file_exists('hello.txt ')){

Echo 'hello.txt exists ';

} Else {

Echo 'hello.txt not exists ';

}

?>

// Output:

Hello.txt exists

File_get_contents-read the entire file into a string

File_put_contents-write a string to a file

File-read the entire file into an array

The code is as follows:

If ($ content = file_get_contents('hello.txt ')){

File_put_contents('hello.txt. bak ', $ content );

}

?>

// A Copy of hello.txt

If ($ content = file('hello.txt ')){

Print_r ($ content );

}

?>

// Array. each row is a group of several members.

Array

(

[0] => Welcome to my blog:

Http://www.phpfensi.com

)

Fileatime-the last time the file was accessed

Filectime-get the inode modification time of the file

Filegroup-the group for obtaining files

Fileinode-get the inode of the file

Filemtime-get file modification time

Fileowner-get the file owner

Fileperms-get file permissions

Filesize-get the file size

Filetype-get file type

The code is as follows:

Echo fileatime('hello.txt ');

Echo filectime('hello.txt ');

Echo filegroup('hello.txt ');

Echo filemtime('hello.txt ');

Echo fileowner('hello.txt ');

Echo substr (sprintf ('% O', fileperms('hello.txt'),-4 );

Echo filesize('hello.txt ');

Echo filetype('hello.txt ');

?>

// Output:

1353329003

1353329003

0

1353330002

0

0666

42

File

Flock-lightweight consultation file locking

Fnmatch-match the file name in the pattern

Fflush-outputs Buffered content to a file

Fpassthru-all the remaining data at the output file pointer

Fscanf-format input from file

Fseek-locate in file pointer

Fstat-get file information through the opened file pointer

Ftell-returned file pointer read/write location

Ftruncate-truncates a file to a specified length

Glob-find the file path that matches the pattern

Is_dir-determine whether the given file name is a directory

Is_executable-determine whether a given file name can be executed

Is_file-determine whether the given file name is a normal file

Is_link-determine whether a given file name is a symbolic connection

Is_readable-determine whether the given file name is readable

Is_uploaded_file-determines whether the file is uploaded through http post.

Is_writable-determine whether a given file name can be written

Is_writeable-is_writable alias

Note: the above functions are used to determine whether a file or directory meets the corresponding conditions. TRUE or FALSE is returned.

Lchgrp-Changes group ownership of symlink

Lchown-Changes user ownership of symlink

Link-create a hard connection

Linkinfo-get the connection information

Lstat-displays information about a file or symbolic connection.

Mkdir-create a directory

Move_uploaded_file-move the uploaded file to a new location

Parse_ini_file-parse a configuration file

Pathinfo-returned file path information

Pclose-disable process file pointer

Popen-open process file pointer

Readfile-output a file

Readlink-returns the target to which the symbolic connection points.

Realpath-returns the normalized absolute path name.

Rename-rename a file or directory

Rewind-position of the inverted file pointer

Rmdir-Delete directory

Set_file_buffer-stream_set_write_buffer alias

Stat-file information

Symlink-create a symbolic connection

Tempnam-create a file with a unique file name

Tmpfile-create a temporary file

Touch-set the file access and modification time

Umask-change the current umask

Clearstatcache-clear the file status cache

Summary: In fact, most of the file operation functions are not used. we can also see how similar these functions are to linux commands.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.