Learn PHP is no longer difficult to master the following commonly used functions

Source: Internet
Author: User
Tags file copy learn php


One, write the file
1. Open resource (file) fopen ($filename, $mode)
2. Write file fwrite ($handle, $STR)
3. Close file fclose ($handle)
4. One-step write File_put_contents ($filename, $str, $mode) file_append lock_ex
}

Second, read the document
1. Read file Fread ($handle, number of bytes)
2. Read a line of fgets ($handle);
3. Read a character fgetc ($handle)
4. Read into an array of file ($filename)
5. One-step read file_get_contents ($filename)

Third, directory operations
1, Build catalog mkdir ($dirname)
2. Delete directory RmDir ($dirname)
3, Open Directory handle Opendir ($dirname)
4, read the number of catalog strips Readdir ($handle)
5, Close directory resource Closedir ($handle)
6, Reset directory resource Rewinddir ($dirname);

Iv. directory and file operations
1. Check if the file or directory exists file_exists ($filename)
2, file or directory rename rename ($file)

v. operation of files
1 copy file copy (' original file ', ' target file ')
2 Deleting Files unlink ($filename)
3 Get File size filesize ($filename)
4 acquisition of file creation time Filectime ($filename)
5 Access time for Files Fileatime ($filename)
6 time to get the file modified Filemtime ($filename)

Vi. Path Operation1 Get Path DirName ($path)
2 Get filename basename ($path)
3 Getting path information PathInfo ($path)

Vii. Array functions (extremely important)

What this post hides 1. Inserts an element at the beginning of the array array_unshift ($arr, $v)
2. Add array elements at the end of the array Array_push ($arr, $v, $v 1 ...)
3. Move the first element of the array out and return this element Array_shift ($arr)
4. Delete element Array_pop ($arr) at the tail of the array
5. Concatenate the array with $separator into a string implode ($a, $arr)
6. Detect if the variable is an array Is_array ($arr)
7. Get the array's key name Array_keys ($arr)
8. Get the value of the array array_values ($arr)
9. Retrieves whether $value is in $arr, returns a Boolean value In_array ($v, $arr)
10. Retrieves the array $arr, whether there is $key this key name Array_key_exists ($k, $arr)
11. Retrieves whether the $value is in $arr, if there is a return key name Array_search ($value, $arr)
12. Reverse an array and, if the second argument is true, keep the key name Array_reverse ($arr, True)
13. Exchanging the keys and values of an array array_flip ($arr)
14. Count the number of array elements ($arr)
15. Count occurrences of all values in the array array_count_values ($arr)
16. Remove duplicate values from the Array_unique ($arr)
17. Values from small to large sorted sort ($arr)
18. Values from large to small sort rsort ($arr)
19. Key from small to large sort ksort ($arr)
20. Key from large to small sort krsort ($arr)
21. Randomly get $num elements from an array array_rand ($arr, $num)
22. Sum all elements of an array array_sum ($arr)
23. Merging Arrays Array_merge ($arr, $arr)
Internal data download, complete PHP source + full set of PHP video tutorial download, please click :http://bbs.itcast.cn/thread-25872-1-1.htm
Subscribe to more PHP learning materials :http://list.qq.com/cgi-bin/qf_invite?id=9b3a12d401be9938323c1871a78074137d00f39064ba450b



Eight, String functions (extremely important)

What's hidden in this post

1. Output string echo ($STR) echo
2. Output as-is (distinguish between single and double quotation marks) print ($STR)
3. Output string, end Script execution Die ($STR):d ie ($str) die;
4. Output string, end Script execution exit ($STR) exit;
5. Output formatted string printf ($str, $p 1,...)
6. Do not output formatted string directly, return formatted string, save to variable sprintf ($str, $p 1,...)
7. Information about printing variables Var_dump ($p)
8. String conversion to lowercase strtolower ($str)
9. Convert string to uppercase Strtoupper ($STR)
10. Convert the first character of a string to uppercase Ucfirst ($STR)
11. Convert each word in a string to uppercase Ucwords ($STR)
12. Remove whitespace characters at both ends of the string. Trim ($str, ', ')
13. Remove the left white space character from the string. Ltrim ($STR)
14. Remove the whitespace character to the right of the string. Rtrim ($STR)
Whitespace characters: "", "\ T", "\ n", "\ R", "s"
15 getting the string length strlen ($str)
16 statistics contains the number of strings Substr_count ($str, ' substring ')
17 returns a substring with a length of $length in the string $string, starting with $start
Substr ($string, $start [, $length])
18 Returns a substring of string $string, $search the first occurrence to the end of the string.
Strstr ($string, $search)
19 Find the first bit of $search in $str, starting with $offset.
Strpos ($str, $search [, int $offset])
20. Find the last position of $search in $str, starting from $offset
Strrpos ($str, $search [, int $offset])
21. Replace all the $search in the $str with the $replace.
Str_replace ($search, $replace, $STR)
22. Repeat the output of the specified string
Str_repeat ()
23. Encrypt strings
MD5 ()
24. String flipping
Strrev ()
25. Use a string to split another string, forming an array//string into an array
Explode ("delimiter", $str);

Learn PHP is no longer difficult to master the following commonly used functions

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.