Webmaster
| |
| class | |
| This declares a class as a template for objects created and used in a script. The objects based on this class are also called instances. To create the class definition, you have to first declare the variables that pertain to this class; a.k.a. the class properties. Next, you define the functions that will be used to interact with an instance and, more specifically, with its data. | |
| Example | class Classname { [var Variable declaration] [Function declaration] } |
| echo | |
| This is not really a function, so it can be used without parentheses. It is used to output one or more strings. If you want to combine characters and variable values, enclose the whole parameter with a pair of double quotes. Single quotes would display the variable names. You can pass several parameters, separating them with commas. | |
| Example | echo , ; |
| flush() | |
| Tries to flush the output buffer content up to the client. | |
| Example | flush(); |
| function() | |
| Declares a function. The instruction is followed by the function name and a pair of parentheses which can be empty or contain a list of parameters used in the function body. Actual arguments will then be passed to the function when it is called up from a script. | |
| Example | function name(param1, param2, etc.) { Instructions } |
| include() | |
| Includes the specified file. | |
| Example | Include("filename.php"); |
| print(string) | |
| Outputs a string or the content of a variable on the page. | |
| Example | <? function write($var) { print("<b>" . $var . "</b>"); } print("The line displays normally<BR>\n"); ecrire("The line displays in bold"); ?> |
| printf(formatted_string) | |
| Outputs a formatted string to screen through the use of special conversion specifications. Here are the main formatting codes used for the various argument types. They are all prefixed with a percentage sign (%): | |
| Code | Description |
| d | Decimal conversion. |
| o | Octal conversion. |
| x, X | Hexadecimal conversion. x uses lowercase letters X uses uppercase letters. |
| b | Binary conversion. |
| c | Character conversion from an ASCII value. |
| s | String conversion. |
| f | Floating point number conversion. |
| e | Floating point number conversion in scientific notation (for instance, 1.3e5). |
| Note that other specifiers can appear between the percentage sign and the type specifier. They are used, for example, to define a padding character, an alignment, a width, or a precision. Here are the main formatting specifiers: | |
| Option | Description |
| - | Right-aligns the string. |
| space character | Produces a space-padded result. |
| 0 | Produces a zero-padded result. |
| ' followed by another character. | Produces a result padded with the specified character. |
| Example: | <? printf("%-9s %5d<BR>\n"); ?> |
| dsjvbfdskvbdlskb | |
| chdir(directory) | |
| Sets the current script execution directory to the specified directory. The function's result is TRUE (returns 1) if the change succeeded, otherwise it is FALSE (returns 0). | |
| Example | <? chdir("/doc") ?> |
| copy(source, destination) | |
| Copies a file using the first argument as the source filename and the second argument as the destination filename. The filenames can be qualified by a relative or absolute path. The function's result is TRUE if the copy operation succeeds, otherwise FALSE. | |
| Example | <? copy("file.zip", "/lowerdir/file.bak")) ?> |
| dir(directory) | |
| Opens the directory referred to by the argument and returns a directory-type object containing two properties: a handle, which references the opened directory, and a path, which contains the directory's path information. The handle can be used with functions such as readdir, among others. | |
| Example | <? $rep = dir("."); ?> |
| feof(file_pointer) | |
| Indicates whether the read position pointer has reached the end of the file referred to by the file pointer given as the argument. | |
| Example | <? feof($fp) ?> |
| file(filename) | |
| Reads the file referred to by the argument and writes its content in a zero-based array. | |
| Example | <? $filearray = file( "text.txt"); ?> |
| file_exists(filename) | |
| The function's result is TRUE (1) if the file named by the argument exists, otherwise it is FALSE. | |
| Example | <? file_exists("file.doc") ?> |
| fileatime(filename) | |
| Returns the time the file given as the argument was last accessed. Note that the result is returned as a UNIX timestamp, i.e. the number of seconds that have elapsed since 1st January 1970.). | |
| Example | <? $acces = fileatime("text.txt"); ?> |
| filectime(filename) | |
| Returns the time the file was last changed. Note that this value is given as a Unix timestamp, i.e. the number of seconds that have elapsed since 1st January 1970. | |
| Example | <? $LastAccess = filectime("file.doc"); ?> |
| filesize(filename) | |
| Returns the size in bytes of the file specified by the argument. | |
| Example | <? filesize("file.zip"); ?> |
| is_dir(filename) | |
| If the filename given as the argument refers to a directory, the function's result is TRUE (1), otherwise it is FALSE (0). | |
| Example | <? is_dir("file.txt") ?> |
| is_executable(filename) | |
| The function's result is TRUE (1) if the file is executable, otherwise it is FALSE (0). | |
| Example | <? is_executable("file.txt") ?> |
| is_readable(filename) | |
| If the file referred to by the argument is readable, the function's result is TRUE (1), otherwise it is FALSE (0). | |
| Example | <? is_readable("file.txt") ?> |
| is_writeable(filename) | |
| If the file referred to by the argument is writable, the function's result is TRUE (1), otherwise it is FALSE (0). | |
| Example | <? is_writeable("file.txt") ?> |
| readfile(filename) | |
| Reads the file specified as the argument and writes the content to the standard output. It returns the number of bytes read. If an error occurs, the function returns FALSE. Note that the function can not only read files from the file system, but also through the http:// and ftp:// protocols, in which case a connection is made to the specified server | |
| Example | <? readfile("file.txt"); ?> |
| rename(old_name, new_name) | |
| Changes the name of the file specified by the first argument for the name given as the second argument. If an error occurs, the function's result is FALSE. | |
| Example | <? rename("file.txt", "document.doc"); ?> |
| touch(filename, time) | |
| This function sets the modification time of the file named by the first argument to the time given by the second argument, which is optional. If the time is not specified, the current time is used. If it is given, it must be a standard Unix timestamp (i.e. the number of seconds that have elapsed since 1st January 1970). | |
| Example | <? touch("document.asc"); ?> |
| phpinfo() | |
| This function returns lots of information regarding your PHP installation, such as which version, the extensions used, the environment variables, etc. Its result is always TRUE. | |
| Example | <? phpinfo(); ?> |
| phpversion() | |
| Returns the version of the PHP module which is run on the server. | |
| Example | <? phpversion(); ?> |
| show_source(filename) | |
| Prints out a version of the file given as the argument with a syntax-highlighted code. | |
| Example | <? show_source("script.php"); ?> |
| getallheaders() | |
| This function writes in an associative array all the HTTP headers of the current request. | |
| Example | <? getallheaders(); ?> |
| header(http_header_string) | |
| This function sends raw HTTP headers. To be successful, it must be called up before any other HTML content is sent. | |
| Example | <? header("Location: http://www.asite.com/"); ?> |
| setcookie(name, value, expire, path, domain, secure) | |
| Defines a cookie to be sent to your visitors. But as cookies must be sent before any other headers, the function call must be placed before any of your HTML tags. The setcookie function offers a great many optional arguments and only the name argument is mandatory. So if you use it without any other arguments, the cookie will immediately be deleted from the user's machine. In all other cases, the cookie is created using the values specified as arguments. Let's examine these optional arguments. The first one, expire, sets the period during which the cookie will be kept on the user's computer. This argument is a regular Unix timestamp (the number of seconds that have elapsed since 1st January 1970). Conversely, if you wish to automatically delete your cookies when your visitors' sessions end, do not supply any value for this expire argument. The next argument, path, specifies the location where the cookie will be stored. The domain argument is the domain name which will be compared to that of the server. If you don't specify one, the server will use its domain. The last argument, secure, allows you to send your cookie in a secure manner, by using the SSL (Secure Socket Layer) protocol. Just specify the value 1 for this argument, in order to make use of this function. |
|
| Example | <? setcookie("Visit", "Yes", time()+86400, "/folder/", ".site.com", 1); ?> |
| mail(recipient, subject, message, headers) | |
| Enables you to send the specified message to the given recipient. You can specify several recipients by separating them with commas. The two other arguments, subject and message (your message body), are also mandatory. The last argument, headers, is optional. It allows you to specify additional SMTP headers in your messages by indicating them one by one, each on a separate line. Notice that on Tripod, the mail() function is limited. You only have the possibility to send mail to 150 recipients a day. That does not mean 150 mails/day, but 150 recipients on To:, Cc: and Bcc: mail fields. Also notice that all headers are accepted, but that From field is set on your Tripod mail adress (login@tripod.co.uk). Last thing, if some adresses are not set in right SMTP format, they will not be count as recipient. If the mail has been sent successfully, the function's result will be TRUE (1). |
|
| Example | <? $mailTo = "webmaster@asite.com"; $mailSubject = "Mail subject"; $mailBody = "This is the text of the message."; $mailBody .= "Message end "; $mailHeaders = "From: user@site.com\n"; mail($mailTo, $mailSubject, $mailBody, $mailHeaders); ?> |
| Return() | |
| Stops the execution of a function and return the value set as argument. | |
| Example | <? return() ?> |
| |