PHP operation file class function, operation URL, etc.

Source: Internet
Author: User
Tags flock

<?php

/**
Reads a file one line at a time (when the file content is large, it applies.) File_get_contents This scene is not very good)
$re = fopen ("index.php", "r+");
while (!feof ($re)) {
$char = fgets ($re);//Fgets gets a row, fgetc gets a character
Echo $char;
}
Fclose ($re);
**/

The second mandatory parameter of the fopen is the open mode;

/**
Multiple processes to write a file, to lock the mechanism
$file = fopen ("indexfile.php", "A +");//A + read and write append, w+ all the contents of the file, re-read and write;
if (Flock ($file, LOCK_EX)) {//Exclusive lock Exclusive
Fwrite ($file, "1111what is You doing\n");
Flock ($file, lock_un);//Release lock unlock
}else{
echo "Flock fail";
}
Fclose ($file);//The function actually calls the release lock
**/


/**
Get file name
Echo basename ("/data/www/test/filesystem.php"), "\ n";
Get directory Name
Echo dirname ("/data/www/test/filesystem.php"), "\ n";
echo __dir__, "\ n";

Manipulate a URL to get related information (note the use of PHP functions
$url _info = Parse_url (' Http://www.google.com/abc/xyz/fck.php?id=1#sharp ');//Parse_url processing URL is sufficient. The Second optional parameter is a PHP constant that takes a value directly from the array
Var_dump ($url _info);
$result = pathinfo ($url _info[' path ');//PathInfo () can info out some information such as file name, directory name, suffix name, etc.
Var_dump ($result);


Array (5) {
["Scheme"]=>
String (4) "http"
["Host"]=>
String "www.google.com"
["Path"]=>
String (+) "/abc/xyz/fck.php"
["Query"]=>
String (4) "Id=1"
["Fragment"]=>
String (5) "Sharp"
}

Array (4) {
["DirName"]=>
String (8) "/ABC/XYZ"
["BaseName"]=>
String (7) "fck.php"
["Extension"]=>
String (3) "PHP"
["FileName"]=>
String (3) "FCK"
}


**/

PHP operation file class function, operation URL, etc.

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.