Home >Backend Development >PHP Tutorial >Dont stop til you get enough A simple summary of PHP function learning
file_exists() Checks whether the file or directory exists |
Description |
bool file_exists (string filename) |
Returns TRUE if the file or directory specified by filename exists, otherwise returns FALSE.
dirname() function returns the directory part of the path.
Syntax
dirname(path) path required. Specifies the path to be checked.
Example
echo dirname("c:/testweb/home.php");
echo dirname("/testweb/home.php");
?>
Output
c:/testweb
/ testweb
You can often see
dirname(__FILE__); What you get is the directory name of the layer where the file is located.
The path of __FILE__ is the file where the current code is located.
preg_split splits the string according to the specified rules.
Syntax: array preg_split(string pattern, string subject, int [limit]);
Return value: array
This function can separate strings according to specified rules. The return value after cutting is an array variable. The parameter pattern is the specified rule string, the parameter subject is the string to be processed, and the parameter limit can be omitted, indicating the maximum number of consistent values to be processed.
implode() function combines array elements into a string
Syntax
implode(separator,array)
separator optional. Specifies what is placed between array elements. Default is "" (empty string).
array required. Arrays to be combined into strings.
file() function reads the entire file into an array.
Similar to file_get_contents(), except that file() returns the file as an array. Each cell in the array is a corresponding line in the file, including newlines.
If failed, return false.
Syntax
file(path,include_path,context)
path required. Specifies the file to be read.
include_path optional. If you also want to search for files in include_path, you can set this parameter to "1".
context Optional. Specifies the environment for a file handle.
context is a set of options that can modify the behavior of the stream. If null is used, it is ignored.
The file_get_contents() function reads the entire file into a string.
Syntax
file_get_contents(path,include_path,context,start,max_length)
path required. Specifies the file to be read.
include_path optional. If you also want to search for files in include_path, you can set this parameter to "1".
context Optional. Specifies the environment for a file handle.
context is a set of options that can modify the behavior of the stream. If null is used, it is ignored.
start optional. Specifies the position in the file to begin reading. This parameter is new in PHP 5.1.
max_length optional. Specifies the number of bytes to read. This parameter is new in PHP 5.1.
ereg() function string comparison analysis. Case sensitive
This function uses pattern rules to parse and compare string strings. The value returned by the comparison result is placed in the array parameter regs. The content of regs[0] is the original string, regs[1] is the first string that conforms to the rules, and regs[2] is the second string that conforms to the rules. string, and so on. If the parameter regs is omitted, it will simply be compared, and the return value will be true if found.
eregi() function string comparison analysis, regardless of case.
Syntax: int eregi(string pattern, string string, array [regs]);
Same as ereg(), except that ereg() is case-sensitive.
str_replace() function uses a string to replace a string of other characters.
Syntax
str_replace(find,replace,string,count)
find required. Specifies the value to be found.
replace required. Specifies the value to replace the value in find.
string required. Specifies the string to be searched for.
count optional. A variable that counts the number of substitutions.
Note: This function is case sensitive. Please use str_ireplace() to perform a case-insensitive search.
preg_match() function
Search the subject string for a match to the regular expression given by pattern.
If matches is provided, it will be populated with the results of the search. $matches[0] will contain text that matches the entire pattern, $matches[1] will contain text that matches the first captured subpattern in parentheses, and so on.
preg_match_all() function string overall comparison analysis.
Syntax: int preg_match_all(string pattern, string subject, array matches, int [order]);
This function uses pattern rules to parse and compare the string subject as a whole. The value returned by the comparison result is placed in the array parameter matches and sorted by the sequence value order. There are two values of parameter order: PREG_PATTERN_ORDER and PREG_SET_ORDER. If there is no order value, the system automatically substitutes PREG_PATTERN_ORDER into the order value. The return value is the number of matching results. If there is no matching result or error, a false value is returned.
strcasecmp() function compares two strings.
The function returns:
0 - if the two strings are equal
<0 - if string1 is less than string2
>0 - if string1 is greater than string2
Syntax
strcasecmp(string1,string2)
string1 required. Specifies the first string to compare.
string2 required. Specifies the second string to be compared.
The above has introduced a simple summary of Dont stop til you get enough PHP function learning, including the content of Dont stop til you get enough. I hope it will be helpful to friends who are interested in PHP tutorials.