PHP — Is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
- Recursive acronym for PHP: Hypertext Preprocessor.
- The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer.
- Is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies.
- Can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, macOS, RISC OS, and probably others.
One of the strongest and most significant features in PHP is its support for a wide range of databases.
Three main areas where PHP scripts are used
- Server-side scripting.
- Command line scripting.
- Writing desktop applications.
Your first PHP-enabled page
<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html>
- Create a file named hello.php and put it in your web server's root directory (DOCUMENT_ROOT).
- Use your browser to access the file with your web server's URL, ending with the /hello.php file reference. When developing locally this URL will be something like http://localhost/hello.php or http://127.0.0.1/hello.php but this depends on the web server's configuration.
Dealing with Forms
Escaping from HTML
<p>This is going to be ignored by PHP and displayed by the browser.</p> <?php echo 'While this is going to be parsed.'; ?> <p>This will also be ignored by PHP and displayed by the browser.</p>
Everything outside of a pair of opening and closing tags is ignored by the PHP parser which allows PHP files to have mixed content.
This allows PHP to be embedded in HTML documents, for example to create templates.
- PHP: Three main areas where PHP scripts are used
- PHP: Your first PHP-enabled page
- PHP: Dealing with Forms
- Dealing with Forms: A simple HTML form
- PHP tags
- PHP tags: If a file contains only PHP code
- PHP: Escaping from HTML
- Escaping from HTML: Advanced escaping using conditions
- PHP: Comments
- PHP primitive types
- PHP types
- integer: Integer overflow
- integer: Converting to integer
- float: Floating point precision
- Syntax: Double quoted
- Syntax: Heredoc syntax
- Syntax: Nowdoc syntax
- String: String access and modification by character
- String: Converting to string
- Variables in PHP
- Predefined Variables
- object: Converting to object
- callback: Passing