Directory Operations (PHP)

Source: Internet
Author: User

1. Create a directory (folder)
MkDir ("./test");
2. Deleting a directory (folder) can only delete empty folders
RmDir ("./test");
3. Move directory (folder)
Rename ("./test", ".. /test11 ");

File operations
Touch ("./test.txt"); Create a file
Copy ("./test.txt", "..   /test.txt "); Copying files
Unlink ("./test.docx"); deleting files

File_get_contents ("./test.txt"); Get file contents: TXT page

File_get_contents ("http://www.baidu.com"); Get content remotely

File_put_contents ("./test.txt", "Hello"); Writing content to a file

ReadFile ("./test.txt"); Get file contents and output directly

File ("./test.txt") reads the contents of the files, returns the array, and each element of the array corresponds to a row

Manipulating the contents of a file
1. Open a file resource
$fp = fopen ("./test.txt", "a");

Manipulating files
echo fgetc ($FP); Read one character at a time
while (!feof ($FP)) determines whether the file is read to the end
{
echo fgetc ($FP);
}
Echo fgets ($FP); Read one line at a time
Echo fgets ($FP);

Echo fread ($FP, 10); Read a specific length
$str = "Ni hao dhakhdak \ r \ n Akdhka";
$str = Iconv ("Utf-8", "gb2312", $str);

Fwrite ($fp, $STR);

2. Close File Resources
Fclose ($FP);

Directory Operations (PHP)

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.