The string manipulation functions in PHP3.0 are more important, as follows:
(1) echo,print,printf,sprintf
Used for output strings. If a variable name is substituted in the string, it is replaced with its value. The latter two functions are similar to C's with the same name function.
String manipulation functions, some of which have exactly the same meaning as the functions of the same name in C. Strrev is to flip a string. Strtolower and Strtoupper convert strings to lowercase and uppercase. Ucfirst is to capitalize the first character of the string. SUBSTR is a substring of the return string, used: substr (string, header, length). The head position is From 0. If it's a negative number, it's from the tail forward.
(3) Chr,ord
A function with the same name.
(4) Explode,implode,join
The function associated with the array. Explode (string, delimiter) returns an array of characters that are produced by separating the string from the separator. Implode (array, delimiter) returns a string that inserts a delimiter between the elements of an array. Join has the same meaning as implode.
(5) Chop
Handles whitespace in the tail of a string.
(6) Htmlspecialchars
Replace the HTML special characters with their names, for example, "<" becomes "<".
(7) NL2BR
Add "<BR>" in front of each carriage return in HTML.
(8) Addslashes,stripslashes
Add "\" to the string and remove "\", for some databases, you must query the character plus and remove "\" before you can query.
(9) Parse_str
Parse the string "Name1=value1&name2=value2& ..." into some variables.
For example: Parse_str ("a=1&b=2"); Generates $a and $b two variables with a value of 1,2. If there are two names that are part of the same name/value, then the last value overrides the previous one. If both pairs have "[]" at the end, such as "a[]=1&a[]=2", the array $a is generated, and the two elements are 1,2 respectively.
Normal expression function
PHP is similar to other Cross-platform languages (perhaps Java is not in its column,:)) and has regular expression functionality. PHP3.0 's regular expression functionality is certainly far less than Perl's, but it's still sufficient, with the main functions:
(1) Ereg,eregi
This is a regular expression matching function, the former is case-insensitive, and the latter is irrelevant.
Usage: Ereg (regular expression, string, [match part array name]);
Regular expressions in PHP3.0 are generally similar to those used in grep.
(2) Ereg_replace,eregi_replace
These are replacement functions.
Usage:
Ereg_replace (Regular expression, substitution string, original string);
A strtr in the string handler is a "translation" function, similar to the tr/.../.../in Perl,
Usage: STRTR (String, "from", "to");
For example: Strtr ("Aaabb", "AB", "CD") returns to "CCCDD".
(3) Split
It's similar to the explode function, but this time you can split the string at a place that matches a regular expression.
Usage:
Split (regular expression, string, [number of items taken out before]);
File action functions
The file manipulation functions in PHP3.0 are roughly similar to C, but there are some extensions, especially in addition to supporting
Access to the native files is also supported for HTTP and FTP URLs, as long as the URL is passed to the file action function as a filename.
These are file information functions, most of which accept a filename as an argument.
(4) FGETSS
Usage:
FGETSS (file number, maximum length);
Read a file line or until the maximum length (similar to fgets), but remove all HTML and PHP tags.
(5) file
Usage:
file (filename);
Returns an array in which each element is a row in the file.
(6) Tempnam
Usage:
Tempnam (directory name, prefix);
Returns a temporary file name.
(7) basename, dirname
Gets the file name section and the Directory name section in the path to the files. Under Windows systems, both "/" and "\" can be used as directory delimiters, and only "/" under other systems.
Directory traversal function
The directory traversal function in PHP is also very common, but it has an "object-oriented" form, so also mention:
(1) dir, Opendir
Usage:
$d = Dir ("directory Name");
$handle = Opendir ("directory Name");
The former returns a directory object, which returns a directory handle. The former returns an object with handle and path two attributes, the first equivalent to the handle returned by Opendir, and the second is the directory name itself. Visit with $d->handle and $d->path.
The first of each group in the three groups is a method of the directory object, called by the object-> method (), and the latter is a function, called by the function name (directory handle). Read is the next filename in the directory. Rewind is the first file name to return to the directory. Close is the directory that is closed and is no longer traversed.
(3) ChDir
Convert PHP's working directory.
Time function
There are some of the time functions in PHP:
(1) Date
Usage:
Date (format, [time]);
If there is no time argument, the current time is used. A format is a string in which the following characters have special meaning:
U replaces the number of seconds y from a starting time (as if it was January 1, 1970) to the 4-digit year.
Y replaces the 2-digit reign.
F replaces the full name of the month in English.
M replaces the English abbreviation of the month.
M replaces the number of months.
Z replaces the number of days since January 1 of the year.
D replaces the number of own.
L REPLACE the English full name of the week.
D replaces the English abbreviation of the day of the week.
W replaces the Day of the Week (number).
H replaces the number of hours (24-hour system).
H replaces the number of hours (12-hour system).
I replace the number of minutes.
s replaces the number of seconds.
A Replace with "AM" or "PM".
A replace with "AM" or "PM".
S replaces the ordinal number suffix, for example: "St", "nd", "rd", "th".
function returns a format string that has been replaced.
(2) getdate (time)
Returns a hash table, each subscript is:
"Seconds"-number of seconds
"Minutes"--fractions
"Hours"--Number of hours
"Mday"--Number of days
"Mon"--Number of months
"Year"--the reign of the year
"Yday"--number of days since January 1
"Weekday"--day of the week, English full name
"Month"--month, full name in English
(3) Gmdate
Similar to date, but first converts time to Greenwich standard.
(4) Mktime
Usage:
Mktime (hours, fractions, seconds, months, days, years); Returns a time value that can be used for other functions.
(5) Time
Usage:
Time (); Returns the number of seconds since Horizon January 1, 1970.
(6) Microtime
Usage:
Microtime (); Returns a string that is divided into two parts with a space, and the latter part equals time ()
Return value, the first part is the number of microseconds.
The year between 1900 and 32767 (including 1900 with 32767);
The month is between 1 and 12;
The day is within the allowable number of days of the month (considering a leap year);
Returns the logic true.
(8) Set_time_limit
Usage:
Set_time_limit (number of seconds);
Specifies that the program must run at the end of a specified number of seconds from the time the sentence is run, and that the program exit with a time-out.
Image function
PHP has a set of image functions, can dynamically generate GIF format image data stream and output to the server. For this set of functions to work, the system must have the GD library support. If it is under UNIX, you should obtain the GD source code and compile it before compiling PHP, and generate LIBGD.A and some. h files, respectively, to the system's library directory and header file directory (for example,/usr/lib and/usr/ If it is under Windows, the PHP3.0 installer installs a Gd.dll file and adds a ' DL (' Gd.dll ') to the program; You can use an image function.
Imagedashedline (Image descriptor, x1,y1,x2,y2, color descriptor);
Imagefill (Image descriptor, starting point x, starting point y, color descriptor);
Imagefilledpolygon (Image descriptor, array of vertices, vertex number, color descriptor);
Imagefilledrectangle (Image descriptor, x1,y1,x2,y2, color descriptor);
Imagefilltoborder (Image descriptor, starting point x, starting point y, boundary color, fill color);
Imageline (Image descriptor, x1,y1,x2,y2, color descriptor);
Imagepolygon (Image descriptor, array of vertices, vertex number, color descriptor);
Imagerectangle (Image descriptor, x1,y1,x2,y2, color descriptor);
Imagesetpixel (Image descriptor, x,y, color descriptor);
Imagestring (image descriptor, font, x,y, string, color descriptor);
Imagestringup (image descriptor, font, x,y, string, color descriptor);
These are the drawing functions that need to be interpreted in order to have the 1th x, 1th y, 2nd x, 2nd y in the vertex array of the polygon in turn,...
(6) Imageloadfont (filename);
The file should be a bitmap font file that returns a font number. The system defaults to 1-5 font numbers and can be used directly.
(7) Imagesx,imagesy
The width and height of an image are obtained, and an image descriptor parameter is received.
Imagecolorset (image descriptor, color descriptor, red, green, blue);
Imagecolorsforindex (image descriptor, color descriptor);
Imagecolorstotal (image descriptor);
The top three returns a color descriptor. Imagecolorexact returns-1 if no match is found.
Imagecolorsforindex returns an array of three items, the elements being red, green, and blue.
Imagecolorstotal returns the total number of colors.
(9) Imagefontheight,imagefontwidth
Receives a font number as an argument.
(10) Imagegif (image descriptor, [filename]);
If no file name is available, the GIF stream is sent to the browser. Then the program should start with a sentence: Header ("Content-type:image/gif")
(11) Imagedestroy (image descriptor);
There is a small bug in the image function (at least in PHP3.0RC and php3.0rc3 for UNIX source code, it has been found that the download file on www.php.net should have been changed), that is, Imagesetpixel always draw points at (Y,y). Whatever the value of x is, this is not a big problem.
Database functions (partial)
PHP's database capabilities should be said to be one of its most useful features. It is characterized by the built-in support for many databases, rather than the need to expand again.
Perl and Tcl are also common cross-platform languages, have strong character ability, the former character ability is stronger, the performance is higher, and the latter has GUI ability. They can all be expanded to support the database, but if you still want your application to have cross-platform capabilities, you need to expand on a variety of platforms, For example, on the UNIX platform for the expansion of Perl DBI package, under Windows 95/nt Perl expansion WIN32::ODBC Package, sometimes this is very troublesome. and PHP, with its built-in database support, saves programmers the hassle.
Access functions are not exactly the same for various databases, such as those based on SQL, which are clearly not accessible in the same way as dBASE or dbm. The following is a more detailed description of the following access functions for the minisql and MySQL databases:
mSQL (mini SQL) is a small relational database that does not perform well and is not fully supported in SQL language, but is sufficient in some network database applications.
MySQL is a variant of msql, with improved performance and increased user access control. Both databases are accessed through the SQL language, but MySQL basically supports all SQL92 specifications, just "Select ... where select ..." Not supported, and some data types are expanded, while mSQL does not support any nested SQL statements, nor does IT support statements such as "Update set Column1=column1-1".
mSQL because it is simpler to run simple SQL statements faster than MySQL, and MySQL thread and index up and down, running complex SQL statements faster than the msql,postgresql,oracle and so on. Security, msql through the ACL file on each host users access rights, the default is all readable/write, and MySQL through a licensing library to set user name, password and access rights, more reliable some msql storage capacity is not very clear, MySQL storage capacity by the file system restrictions, For example, under Linux can not be more than 2G (3G? Don't remember clearly).
mSQL and MySQL since it is almost two things, PHP access to their statements are similar, for example, Msql_close and Mysql_close respectively to complete the same close action. So the following introduction is only for MySQL introduction, mSQL Access statements can only be replaced with a prefix (otherwise specified).
Note: Both mSQL and MySQL access functions need to have the appropriate permissions to run.
(1) mysql_connect (host, username, password);
Returns a connection number.
Note: MySQL user password can vary depending on the user's machine IP address. In addition, mSQL does not have a username mechanism, so msql_connect only needs one host parameter. The host can be an IP address or a domain name.
If the SQL statement is a SELECT, a result number is returned. Otherwise the returned value can be ignored.
Returns False if it fails.
(5) Mysql_fetch_array (result number);
Remove the next row and return an array. Can be accessed with a digital subscript (the first field is subscript 0), or you can use a string subscript access (that is, use each field name). Returns False if the last row has been taken.
If no field number, remove a field. Returns a hash table labeled: Name, table, Max_length, Not_null, Primary_key, Unique_key, Multiple_key, numeric, blob, type, unsigned, zero Fill each subscript the meaning should be more clear.
Is exactly like Mysql_connect, but establishes a "permanent connection" that is never closed once established, even when the Mysql_close function or program is executed. The next time you attempt to establish a permanent connection, the system discovers that a permanent connection already exists. The connection number is returned directly without being recreated.
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.