← PHP EnglishChapter 01 of 13

Introduction to PHP

## Learning Objectives - Understand PHP history and role in web development - Set up PHP development environment - Write and run your first PHP program - Understand PHP syntax basics ## What is PHP? PHP (Hypertext Preprocessor) is a server-side scripting language primarily used for web development. It powers millions of websites and applications worldwide. ```php ``` ## PHP Platform ### Key Features - **Server-Side** - Code executes on the server, not the browser - **Cross-Platform** - Runs on Windows, Linux, macOS - **Database Support** - Native support for MySQL, PostgreSQL, and more - **Open Source** - Free to use and distribute - **Embedded** - Can be embedded directly into HTML ### Common Uses - Dynamic web pages - Content management systems (WordPress, Drupal) - E-commerce platforms (Magento, WooCommerce) - RESTful APIs - Command-line scripts ## Installing PHP ### Download Get PHP from or use pre-built packages: - **Windows**: XAMPP, WampServer, or official Windows builds - **Linux**: `sudo apt install php` (Ubuntu/Debian) - **macOS**: Built-in or Homebrew (`brew install php`) ### Verify Installation ```bash php --version ``` ### Running PHP ```bash php script.php ``` ## Your First Program ### File: hello.php ```php ``` ### Run ```bash php hello.php # Output: Hello, World! ``` ### Embedded in HTML ```php My First PHP Page

Today's date:

``` ## PHP Syntax Basics ### Tags PHP code must be enclosed in `` tags: ```php ``` Short tags ` ``` ### Statements Each statement ends with a semicolon: ```php ``` ### Comments ```php ``` ## Outputting Data ### echo ```php ``` ### print ```php ``` ### print_r ```php ``` ### var_dump ```php ``` ## Variables ### Declaration Variables in PHP start with `$`: ```php ``` ### Naming Rules - Start with `$` followed by letter or underscore - Can contain numbers (after first character) - Case-sensitive - No spaces allowed ```php ``` ## Data Types PHP supports several data types: ```php ``` ## Constants ### define() ```php ``` ### const ```php ``` ## Superglobals PHP provides built-in superglobal variables: ```php ``` ## PHP in Web Context ### Form Handling ```php
``` ```php ``` ## IDEs and Editors ### Popular Options - VS Code with PHP Intelephense extension - PhpStorm (recommended, paid) - Sublime Text - NetBeans - Eclipse PDT ## PHP Versions | Version | Year | Features | |---------|------|----------| | PHP 7 | 2015 | Scalar type hints, return types | | PHP 8 | 2020 | Named arguments, attributes, match | | PHP 8.1 | 2021 | Enums, readonly properties | | PHP 8.2 | 2022 | Constants in traits, readonly classes | | PHP 8.3 | 2023 | Typed class constants, json_validate | Check your version: ```bash php --version ``` ## Summary - PHP is server-side scripting for web development - Code goes between `` tags - Variables start with `$` (e.g., `$name`) - Use `echo` or `print` for output - `define()` or `const` for constants - Superglobals access server/request data - PHP 8.x is current; use modern features

Comments

Comments powered by Giscus

To enable comments, add your Giscus embed code here.

Learn more about Giscus →