| Start |
|---|
| HTML output from web server PHP can be used to add content to HTML files. While HTML is processed directly by a web browser, PHP scripts are executed by a web server and the resulting HTML is sent to the browser. The following HTML markup contains a PHP statement that will add When this is saved as a PHP script and executed by a web server, the following HTML will be sent to the user's browser:
For example, consider the following code: Its output is identical to the output of the following: In real-world applications, all data output by PHP to an HTML page should be properly escaped to prevent XSS (Cross-site scripting (opens new window)) attacks or text corruption. See also: Strings (opens new window) and PSR-1 (opens new window), which describes best practices, including the proper use of short tags ( |
| Hello, World! The most widely used language construct to print output in PHP is Alternatively, you can also use Both statements perform the same function, with minor differences:
Both C-style See Outputting the value of a variable (opens new window) for a comprehensive introduction of outputting variables in PHP. |
| Non-HTML output from web server In some cases, when working with a web server, overriding the web server's default content type may be required. There may be cases where you need to send data as The Consider the following code, where we set This will produce a plain text document with the following content: Hello World To produce JSON (opens new window) content, use the This will produce a document of type {"response":"Hello World"} Note that the This will produce a warning: Warning: Cannot modify header information - headers already sent by (output started at /dir/example.php:2) in /dir/example.php on line 3 When using View the output buffering section (opens new window) to learn how to 'catch' your content into a variable to output later, for example, after outputting headers. |
| PHP built-in server PHP 5.4+ comes with a built-in development server. It can be used to run applications without having to install a production HTTP server such as nginx or Apache. The built-in server is only designed to be used for development and testing purposes. It can be started by using the Example usage
ConfigurationTo override the default document root (i.e. the current directory), use the E.g. if you have a LogsEvery time a request is made from the development server, a log entry like the one below is written to the command line. |
| PHP CLI PHP can also be run from command line directly using the CLI (Command Line Interface). CLI is basically the same as PHP from web servers, except some differences in terms of standard input and output. TriggeringThe PHP CLI allows four ways to run PHP code:
Input |
| Instruction Separation Just like most other C-style languages, each statement is terminated with a semicolon. Also, a closing tag is used to terminate the last line of code of the PHP block. If the last line of PHP code ends with a semicolon, the closing tag is optional if there is no code following that final line of code. For example, we can leave out the closing tag after However, if there is any other code following your PHP code block, the closing tag is no longer optional: We can also leave out the semicolon of the last statement in a PHP code block if that code block has a closing tag: It is generally recommended to always use a semicolon and use a closing tag for every PHP code block except the last PHP code block, if no more code follows that PHP code block. So, your code should basically look like this: |
| PHP Tags There are three kinds of tags to denote PHP blocks in a file. The PHP parser is looking for the opening and (if present) closing tags to delimit the code to interpret. Standard TagsThese tags are the standard method to embed PHP code in a file. Echo TagsThese tags are available in all PHP versions, and since PHP 5.4 are always enabled. In previous versions, echo tags could only be enabled in conjunction with short tags. Short TagsYou can disable or enable these tags with the option Short tags:
ASP TagsBy enabling the These are an historic quirk and should never be used. They were removed in PHP 7.0. RemarksPHP (opens new window) (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source programming language. It is especially suited for web development. The unique thing about PHP is that it serves both beginners as well as experienced developers. It has a low barrier to entry so it is easy to get started with, and at the same time, it provides advanced features offered in other programming languages. Open-Source It's an open-source project. Feel free to get involved (opens new window). Language Specification PHP has a language specification (opens new window). Supported Versions Currently, there are three supported versions (opens new window): 5.6, 7.0 and 7.1. Each release branch of PHP is fully supported for two years from its initial stable release. After this two year period of active support, each branch is then supported for an additional year for critical security issues only. Releases during this period are made on an as-needed basis: there may be multiple point releases, or none, depending on the number of reports. Unsupported Versions Once the three years of support are completed, the branch reaches its end of life and is no longer supported. A table of end of life branches (opens new window) is available. Issue Tracker Bugs and other issues are tracked at https://bugs.php.net/ (opens new window). Mailing Lists Discussions about PHP development and usage are held on the PHP mailing lists (opens new window). Official Documentation Please help to maintain or to translate the official PHP documentation (opens new window). You might use the editor at edit.php.net (opens new window). Check out our guide for contributors (opens new window). |
Read Article
https://develop.horje.com/learn/1434/reference