Full Transcript

PHP Unit – 1 Introduction of PHP : What is PHP?  PHP is an acronym for "PHP: Hypertext Pre processor"  PHP is a widely-used, open source scripting language  PHP scripts are executed on the server  PHP is free to download and use What is a PHP...

PHP Unit – 1 Introduction of PHP : What is PHP?  PHP is an acronym for "PHP: Hypertext Pre processor"  PHP is a widely-used, open source scripting language  PHP scripts are executed on the server  PHP is free to download and use What is a PHP File?  PHP files can contain text, HTML, CSS, JavaScript, and PHP code  PHP code is executed on the server, and the result is returned to the browser as plain HTML  PHP files have extension ".php" What Does PHP Do?  PHP can generate dynamic page content  PHP can create, open, read, write, delete, and close files on the server  PHP can collect form data  PHP can send and receive cookies  PHP can add, delete, modify data in your database  PHP can be used to control user-access  PHP can encrypt data Why PHP?  PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)  PHP is compatible with almost all servers used today (Apache, IIS, etc.)  PHP supports a wide range of databases  PHP is free. Download it from the official PHP resource: www.php.net  PHP is easy to learn and runs efficiently on the server side PHP Asst. Prof. Pradnya Nehete TY BCA KKSU A brief History of PHP : Here’s a brief history of PHP in points: 1. 1994: Rasmus Lerdorf creates PHP as a simple tool to track visits to his online resume. 2. 1995: Released as "PHP/FI" (Personal Home Page/Form Interpreter) for public use, enabling simple dynamic websites. 3. 1997: Zeev Suraski and Andi Gutmans rewrite the core of PHP. 4. 1998: PHP 3 is released, making it a popular tool for web development. 5. 2000: PHP 4 is launched, powered by the Zend Engine, offering better performance and scalability. 6. 2004: PHP 5 introduces improved object-oriented programming (OOP) support. 7. 2015: PHP 7 is released with major performance boosts and enhanced error handling. 8. Present: PHP continues to evolve, powering many websites and platforms like WordPress. Installing PHP : Step 1: Click on the above link provided to download the XAMPP server according to your window requirement. PHP Asst. Prof. Pradnya Nehete TY BCA KKSU Step 2: After downloading XAMPP, double click on the downloaded file and allow XAMPP to make changes in your system. A window will pop-up, where you have to click on the Next button. PHP Asst. Prof. Pradnya Nehete TY BCA KKSU Step 3: Here, select the components, which you want to install and click Next. Step 4: Choose a folder where you want to install the XAMPP in your system and click Next. Step 5: Click Next and move ahead. PHP Asst. Prof. Pradnya Nehete TY BCA KKSU Step 6: XAMPP is ready to install, so click on the Next button and install the XAMPP. Step 7: A finish window will display after successful installation. Click on the Finish button. PHP Asst. Prof. Pradnya Nehete TY BCA KKSU Step 8: Choose your preferred language. Step 9: XAMPP is ready to use. Start the Apache server and MySQL and run the php program on the localhost. How to run PHP programs on XAMPP, see in the next tutorial. PHP Asst. Prof. Pradnya Nehete TY BCA KKSU Step 10: If no error is shown, then XAMPP is running successfully. Basics : PHP Asst. Prof. Pradnya Nehete TY BCA KKSU Lexical Structure : The lexical structure in PHP defines how PHP scripts are written and interpreted, including rules for tokens, identifiers, keywords, literals, and comments. Here's a breakdown: ### 1. Tokens - Tokens are the smallest building blocks in PHP and include keywords, operators, identifiers, literals, and punctuation. - PHP scripts are broken down into tokens when the code is parsed. ### 2. Identifiers - Identifiers are names used to identify variables, functions, classes, etc. - Rules: - Must start with a letter or an underscore (_). - Can contain letters, numbers, and underscores. - Case-sensitive (e.g., $myVar and $MyVar are different). Example: php $name = "PHP"; // 'name' is an identifier ### 3. Keywords - PHP has reserved keywords for specific tasks, such as if, while, function, and class. - Keywords cannot be used as identifiers (variable or function names). Example: PHP Asst. Prof. Pradnya Nehete TY BCA KKSU php function myFunction() { // 'function' is a keyword // function body } ### 4. Literals - Literals are values directly written in the code (e.g., numbers, strings). - Types include: - String literals: Text enclosed in single (') or double (") quotes. - Integer literals: Whole numbers like 123. - Floating-point literals: Decimal numbers like 123.45. Example: php $age = 30; // Integer literal $price = 29.99; // Floating-point literal $name = "PHP"; // String literal ### 5. Comments - Comments are ignored by the PHP interpreter and are used to explain code. - Single-line comments: // or # - Multi-line comments: Example: PHP Asst. Prof. Pradnya Nehete TY BCA KKSU php // This is a single-line comment # Another single-line comment ### 6. Whitespace and Line Breaks - Whitespace (spaces, tabs, newlines) is generally ignored in PHP except in strings and certain situations. - It's used to make the code more readable. Example: php $x = 5; // Whitespace is ignored between tokens ### 7. Operators - PHP supports various operators, including arithmetic (+, -, *), comparison (==, >, - Use Case: Useful when you need to inject dynamic content at various points in the HTML structure. ### 5. Using HTML Inside PHP - You can also output HTML from within PHP code using echo or print. - Example: php - Use Case: For generating larger sections of HTML programmatically from PHP. PHP Asst. Prof. Pradnya Nehete TY BCA KKSU ### 6. Combining PHP Logic and HTML - You can use PHP to include logic, like conditionals or loops, that dynamically outputs HTML content. - Example: html - Use Case: Dynamically generating lists, tables, forms, etc., based on data. ### 7. Avoid Mixing PHP Logic and HTML - Best practice is to separate logic (PHP) and presentation (HTML) to keep code clean and maintainable. - Example: php PHP Asst. Prof. Pradnya Nehete TY BCA KKSU - Use Case: Cleaner code structure by separating PHP logic from HTML output. ### 8. Embedding PHP in JavaScript - PHP can be used within JavaScript for dynamic values or logic. - Example: html var count = ; alert("Count is: " + count); - Use Case: Dynamic interaction between PHP and client-side JavaScript. ### 9. PHP in Forms - PHP can be used to dynamically populate form fields or process form data. - Example: html Name:

Use Quizgecko on...
Browser
Browser