PHP3 Chinese Document continued 6

Source: Internet
Author: User
Tags ereg rewind

The character string operation function PHP3.0 has many character string operations, including (1) echo, print, printf, and sprintf. if there is a variable name in the string, it is replaced with its value. the last two functions are similar to C functions with the same name. (2) strchr, strlen, strtok, strrchr, strrev, strstr, strtolower, strtoupper, substr, and ucfirst use string operation functions. Some functions with the same name in C have the same meaning. strrev is used to flip a string. strtolower and strtoupper convert strings to lower case and upper case. ucfirst converts the first character of a string to uppercase. substr is a substring of the returned string. Its usage is substr (string, header, length ). the header position is counted from 0. if it is a negative number, it indicates the forward number from the tail. (3) functions with the same name as Chr and Ord. (4) explode, implode, and join functions related to arrays. explode (string, delimiter) returns an array generated when the string is split. implode (array, delimiter) returns a string that inserts a delimiter into each element of the array. join and implode have the same meaning. (5) The gap at the end of the Chop processing string. (6) htmlspecialchars replaces special HTML characters with their names, for example, "<" to "<". (7) Add "nl2br" to each carriage return in HTML"
". (8) AddSlashes and StripSlashes Add "" and remove "" to the string as needed. For some databases, you must add and remove "" to the characters to be queried before querying. (9) parse_str "name1 = value1 & name2 = value2 &... "Type string is analyzed into some variables. for example: parse_str ("a = 1 & B = 2"); generate two variables $ a and $ B, with values 1, 2, respectively. if two pairs of Names/values have the same name, the latter value overwrites the previous one. if the two pairs have "[]" at the end, for example, "a [] = 1 & a [] = 2", an array $, the two elements are respectively 1, 2. regular Expression functions PHP and other cross-platform languages (maybe Java is not listed here. :)) Similarly, the regular expression function is also available. the Regular Expression Function of PHP3.0 is far inferior to Perl, but it is still enough. The main functions are as follows: (1) ereg and eregi. This is a regular expression matching function, and the former is case-sensitive, the latter is irrelevant. usage: ereg (Regular Expression, String, [matching partial array names]); Regular Expression in PHP3.0 is similar to that in grep. (2) ereg_replace and eregi_replace are replacement functions. usage: ereg_replace (Regular Expression, replacement string, original string); There is a strtr in the string processing function, which is a "Translation" function, similar to tr /... /... /, usage: strtr (string, "from", "to"); for example, strtr ("aaabb", "AB", "cd") returns "cccdd ". (3) The split function is similar to the explode function, but this time the string can be separated by matching a regular expression. usage: split (Regular Expression, String, [how many items are taken out before]); file operation functions in PHP3.0 are similar to those in C, but there are some extensions, in particular, in addition to accessing local files, you can also access HTTP and FTP URLs. You only need to pass these URLs as file names to file operation functions. main file operation functions include: (1) fclose, feof, fgetc, fgets, fopen, fputs, fseek, ftell, mkdir, readlink, rename, rewind, rmdir, stat, unlink functions are similar to functions with the same name in C. (2) The meanings of chgrp, chmod, chown, and copy functions are also easy to understand: chgrp (file name, group); chmod (file name, mode); chown (file name, user); copy (source file name, target file name); note that these functions use the file name instead of the file number returned by fopen. (3) file_exists, fileatime, filectime, filegroup, fileinode, filemtime, fileowner, filesize, filetype, fileperms, fileumask, is_dir, is_executable, is_file, is_link, is_readable, is_writeable these are file information functions. Most of them accept a file name as a parameter. (4) fgetss usage: fgetss (file number, maximum length); read a row of the file or until the maximum length (similar to fgets), but remove all HTML and PHP markup. (5) file Usage: file (file Name); returns an array, each element is a row in the file. (6) tempnam usage: tempnam (directory name, prefix); returns a temporary file name. (7) Get the file name and directory name in the file path by basename and dirname. in Windows, "/" and "" can both be used as Directory delimiters. In other systems, only "/" can be used. the directory traversal function in PHP is also very common, but it has an "Object-Oriented" form, so we also mention: (1) dir, opendir usage: $ d = dir ("directory name"); $ handle = opendir ("directory name"); the former returns a directory object, and the latter returns a directory handle. the former returns two attributes: handle and path. The first is equivalent to the handle returned by opendir, and the second is the directory name. $ d-> handle and $ d-> path are used for access. (2) read, readdir, rewind, rewinddir, close, and closedir. The first method in each group is the directory object, which is called using "Object-> method, the next one is a function called by "function name (directory handle. read is the next file name in the returned directory. rewind is the first file name to return to the directory. close is to close the Directory and stop traversing. (3) convert chdir to the PHP working directory. the time functions in PHP are as follows: (1) date usage: date (format, [time]); if there is no time parameter, the current time is used. the format is a string. The following characters have special meanings: U is replaced with a four-digit year number in seconds since the start time (like January 1, January 1, 1970. y is replaced with the 2-digit year number. F is replaced with the full name of the month. M is replaced with the abbreviation of the month. m is replaced with the monthly number of copies. z is replaced by the number of days since January 1 of the current year. d. Replace it with the daily number. l replace it with the full name of the day of the week. d. Replace it with the abbreviation of the day of the week. w is replaced with the day of the week (number ). replace H with the hour (in the 24-hour format ). replace h with the hour (in 12-hour format ). replace I with the number of minutes. replace s with the number of seconds. A is replaced with "AM" or "PM ". a is replaced with "am" or "pm ". S is replaced with a sequential numeric suffix, for example, "st", "nd", "rd", "th ". the function returns a formatted string that has been replaced. (2) getdate (time) returns a hash table with the following subscripts: "seconds" -- seconds "minutes" -- score "hours" -- hours "mday" -- Number of days "mon" -- number of months "year" -- number of years "yday" -- Number of days since January 1, January 1" weekday "-- day of the week, the full name "month" -- month. The full name (3) gmdate is similar to date, but the time is first converted to Greenwich Mean Time. (4) mktime usage: mktime (hours, scores, seconds, months, days, and years); returns a time value for other functions. (5) time usage: time (); returns the number of seconds since, January 1, January 1, 1970. (6) microtime usage: microtime (); returns a string, which is divided into two parts by space. The latter part is equivalent to the return value of time (), and the first part is the number of microseconds. (7) checkdate usage: checkdate (month, day, year); returns logical truth or logical false. if the year is between 1900 and 32767 (including 1900 and 32767), the month is between 1 and 12, and the day is within the allowed number of days of the month (considering the leap year ); returns the logical truth. (8) set_time_limit usage: set_time_limit (number of seconds). It indicates that the program must end in the specified number of seconds from the time of running the sentence, and the program will exit due to an error. the image function PHP contains a set of image functions that can dynamically generate image data streams in gif format and output them to the server. for this set of functions to work, the gd library must be supported in the system. in Unix, the source code of gd should be obtained and compiled before PHP is compiled to generate libgd. a and some. copy the H file to the system's library directory and header file directory (for example,/usr/lib and/usr/include). If it is in Windows, PHP3.0 will install a gd. dll file, add a dl ("gd. dll "); you can use the image function. the main image functions are: (1) ImageCreate (width, height) returns an image descriptor. (2) ImageCreateFromGif (File Name); returns an image descriptor. (3) ImageColorAllocate (Image Descriptor, red, green, blue); returns a color descriptor. since a Gif image can only have 256 colors, you must first assign a palette to it. This statement is to assign a palette item. (4) ImageColorTransparent (Image Descriptor, color descriptor); specify a color as transparent. (5) ImageArc (Image Descriptor, center x coordinate, center y coordinate, elliptical width, elliptical height, starting angle, ending angle, color descriptor); ImageChar (Image Descriptor, Font, x, y, character, color descriptor); ImageCharUp (Image Descriptor, Font, x, y, character, color descriptor); ImageCopyResized (Target Image Descriptor, source Image Descriptor, target x, target y, source x, source y, target width, target height, Source width, and source height); ImageDashedLine (Image Descriptor, x1, y1, x2, y2, color descriptor ); imageFill (Image Descriptor, starting point x, starting point y, color descriptor); ImageFilledPolygon (Image Descriptor, each vertex array, number of vertices, 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, each vertex array, number of vertices, 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 drawing functions. What needs to be explained is that the vertex array of the polygon stores the first vertex x, the first vertex y, the second vertex x, the second vertex y ,... (6) ImageLoadFont (File Name); the file should be a bitmap font file and return a font number. the system defaults to 1-5 font numbers, which can be used directly. (7) ImageSX and ImageSY obtain the width and height of an image and receive an Image Descriptor parameter. (8) ImageColorAt (Image Descriptor, x, y); ImageColorClosest (Image Descriptor, red, green, blue); ImageColorExact (Image Descriptor, red, green, blue ); imageColorSet (Image Descriptor, color descriptor, red, green, blue); ImageColorsForIndex (Image Descriptor, color descriptor); ImageColorsTotal (Image Descriptor); the first three return a color descriptor. imageColorExact if no matching is found,-1 is returned. imageColorsForIndex returns an array of three elements: Red, green, and blue. imageColorsTotal returns the total number of colors. (9) ImageFontHeight, ImageFontWidth receives a font number as a parameter. (10) ImageGif (Image Descriptor, [file name]); if no file exists

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.