php basics0203233323333333333333333333333333

kshahabaj528 11 views 11 slides Oct 03, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

php basics


Slide Content

PHP Basics Introduction to PHP Programming Presented by: Shahabaj Khan

Introduction to PHP • What is PHP? - PHP: Hypertext Preprocessor - Server-side scripting language - Widely used for web development • Why use PHP? - Easy to learn - Open-source - Cross-platform

PHP Syntax Overview • Basic Structure: <?php // PHP code goes here ?> • PHP Tags: - Opening tag: <?php - Closing tag: ?>

Variables in PHP $variable_name = value; Example: $name = "John"; $age = 25; Variables start with $, are case-sensitive, and do not require explicit type declaration.

Data Types in PHP Common Data Types: • String • Integer • Float • Boolean • Array • Object

PHP Operators Types of Operators: • Arithmetic: +, -, *, / • Assignment: =, +=, -= • Comparison: ==, !=, >, < • Logical: &&, ||, !

Control Structures in PHP Conditional Statements: if (condition) { // code to execute if true } elseif (condition) { // code for elseif } else { // code to execute if false } Loops: • while • for • foreach

Functions in PHP Definition: function functionName() { // code to execute } Example: function sayHello() { echo "Hello, World!"; }

Working with Forms in PHP HTML Form Example: <form method="POST" action="submit.php"> Name: <input type="text" name="name"> <input type="submit"> </form> PHP Script to Handle Form: $name = $_POST["name"]; echo "Hello, " . $name;

File Handling in PHP Basic Operations: • fopen(), fread(), fwrite(), fclose() Example: $file = fopen("test.txt", "r"); echo fread($file, filesize("test.txt")); fclose($file);

PHP and MySQL Connecting to a Database: $conn = mysqli_connect("hostname", "username", "password", "database"); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }
Tags