0% found this document useful (0 votes)
10 views6 pages

PHP

The document provides an overview of various web development concepts, including web servers, PHP functions, and jQuery. It covers topics such as loops, string functions, array functions, form submission methods (GET and POST), and database interactions using MySQLi. Additionally, it discusses object-oriented programming principles, cookies, sessions, and AJAX, along with examples and syntax for better understanding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

PHP

The document provides an overview of various web development concepts, including web servers, PHP functions, and jQuery. It covers topics such as loops, string functions, array functions, form submission methods (GET and POST), and database interactions using MySQLi. Additionally, it discusses object-oriented programming principles, cookies, sessions, and AJAX, along with examples and syntax for better understanding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Unit -1

Web Server-it is a software which serves websites on the internet, to achieve a particular goal it acts as a
middleman between the server and the client.
Internet Information Services (IIS) – It is a flexible, general-purpose web server from Microsoft that runs on
Windows systems to serve requested HTML pages or files.
Loops: While , do..while ,for , foreach
Foreach loop: The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.
Ex: <?php String function: 1 strlen():- Return the Length of a String
$colors = array("red", "green", "blue", "yellow"); 2 str_word_count() - Count Words in a String
foreach ($colors as $value) { 3. strrev() - Reverse a String
echo "$value <br>"; } ?> 4 strtoupper() - converts a string to uppercase
Default argument function: <?php 5 strtolower() - converts a string to lowercase
function greeting($name="GeeksforGeeks") 6 Trim() Removes whitespace or other characters from both sides
{ echo "Welcome to $name "; of a string
echo("\n"); } 7 str_replace(), strcmp(),strpos(),str_split()
greeting("Gfg"); ex: <?php
// Passing no value echo strlen(“hello world”); ?>
greeting(); Math function 1 abs() :returns absolute value of given number
greeting("A Computer Science Portal"); 2 ceil() function rounds fractions up. >3.3 >4
?> 3 floor() function rounds fractions down> 3.4>3
Array functions:1 array() function creates and 4 sqrt() function returns square root of given argument
returns an array. 5 decbin() function converts decimal number into binary
2 count() function counts all elements in an array. 6 dechex() , decoct(), bindec()
Ex: <?php 7 round() function is used to find rounds a float number.
$season=array("summer","winter","spring","autumn"); ex: echo round(3.0978645);
echo count($season); // output: 4 ?> 8 pow() , Rand() ,Max(),min(),
3 sort() function sorts all the elements in an array. Date function:
4 rsort()Sort the elements in descending getdate() , date_add(), date_create() , date_format() ,
alphabetical order checkdate(), time(),
5 array_search() searches the specified value in an array
6 array_change_key_case(),asort(),arsort(),
array_merge(),array_sum(),array_diff_key()

func_num_args() It returns the total number of arguments provided in the function call operation. For example, if
"func_num_args()" returns 1, you know that there is only 1 argument provided by calling code.
Ex: <?php
function f1()
{ $numargs = func_num_args();
echo "Number of arguments: $numargs\n"; }
f1(1, 2, 3); // Prints 'Number of arguments: 3'
?>
POST method: The POST method transfers information via HTTP headers. The example below displays a simple
HTML form with two input fields and a submit button:
GET Method: The GET method sends the encoded user information appended to the page request. The page and
the encoded information are separated by the ? character
<html> <html>
<body> <body>
<form action="welcome.php" method="post"> Welcome <?php echo $_POST["name"]; ?><br>
Name: <input type="text" name="name"><br> Your email address is: <?php echo $_POST["email"]; ?>
E-mail: <input type="text" name="email"><br> </body> </html>
<input type="submit">
</form>
</body> </html
PHP-Personal Home Page.
PHP was created by Rasmus Lerdorf in 1994.
PHP files have extension ".php"
______ function returns the number of arguments passed into user-defined function<<fun_num_arg()
_____ function is used to replace<<str_replace()
Unit-2 JSON: JavaScript Object Notation
AJAX: (Asynchronous JavaScript And XML)
GD libaray function: • imagedestroy — Destroy an image
• getimagesize — Get the size of an image
• imagearc — Draws an arc
• imagechar — Draw a character horizontally
• imagecopy — Copy part of an image
Methods to submit form: GET and POST
GD? (Graphics Draw)
• In PHP ________ superglobal variable is used to get cookie. ($_COOKIE)
• _______ function is used to set the cookie. (setcookie())
• Session variables are set with the ________ super global variable. ($_SESSION)
• A PHP session is started with the_______ function. (session_start())
• ______ function is used to destroy the session. (session_destroy())

Unit-3 mysqli_connect() is a function in PHP used to connect to a MySQL database server.


Ex:$conn = mysqli_connect("localhost", "root", "", "my_database");
sqli_num_rows() counts the number of rows in a result set returned by a SELECT query
mysqli_query() executes a query (like SELECT, INSERT, UPDATE, DELETE) against the database
mysqli_insert_id() returns the ID of the last inserted row (when using an auto-increment column).
Unit-4 jQuery is a JavaScript Library. • jQuery greatly simplifies JavaScript programming. • jQuery is a lightweight,
"write less, do more", JavaScript library. • The purpose of jQuery is to make it much easier to use JavaScript on your
website.
jQuery Selectors: $("#id"), $(".class"), $("div"), $("[href]"),element, universal ,first,last
jQuery Events .click(), .dblclick(), .mouseenter(), .mouseleave(), .focus(),.sumbit()
jQuery Effects .hide(), .show(), .toggle(), .fadeIn(), .slideUp(),.Animate()
Which jQuery effect is used to hide the content? .hide() method
Which method sets or returns one or more style properties for the selected elements? .css() method.
unit-5
• OOP stands for ______.object oriented programming
• In PHP the construct function starts with _______. (Ans: two underscores (__))
• A _____allows you to initialize an object's properties upon creation of the object. ( constructor)
• ______ is known as Scope Resolution Operator. (::)
• A ______is called when the object is destructed or the script is stopped or exited. (destructor)
• A _____function that is automatically called when you create an object from a class.( __construct())
• A ______ function that is automatically called at the end of the script. (__destruct())
• Class- A class is like a blueprint, template, or design. It defines properties and methods
• Object- An object is a real instance of a class. When you create an object from a class, it has real values.

A class is defined by using the class keyword, followed by the name of the class and a pair of curly braces ({}). All
its properties and methods go inside the braces
Objects are instance of classs Classes are nothing without objects! We can create multiple objects from a class.
Each object has all the properties and methods defined in the class, but they will have different property values.
Unit-2
A cookie :is a small file that the server embeds on the user's computer. A cookie is often used to identify a user.
Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both
create and retrieve cookie values.
PHP cookie is a small piece of information which is stored at client browser. Cookie is created at server side and
saved to client browser.
Ex : setcookie(name, value, expire, path, domain, secure, httponly);
A session is a way to store information (in variables) to be used across multiple pages.
PHP session is used to store and pass information from one page to another temporarily (until user close the
website).
PHP session technique is widely used in shopping websites where we need to store and pass cart information e.g.
username, product code, product name, product price etc from one page to another.
Ex: <?php
session_start(); ?>
// Set session variables
$_SESSION["favcolor"] = "red";
$_SESSION["favhero"] = "Swami Vivekanand";
echo "Session variables are set.";
?>
A regular expression is a sequence of characters that forms a search pattern. When you search for data in a text,
you can use this search pattern to describe what you are searching for. A regular expression can be a single
character, or a more complicated pattern. Regular expressions help you accomplish tasks such as validating email
addresses, IP address etc.
• POSIX Regular Expressions
Brackets:Brackets ([]) have a special meaning when used in the context of regular expressions. They are used to
find a range of characters
Quantifiers :The frequency or position of bracketed character sequences and single characters can be denoted by a
special character. The +, *, ?, {int. range}, and $ flags all follow a character sequence.
• PERL Style Regular Expressions
ereg() The ereg() function searches a string specified by string for a string specified by pattern, returning true if the
pattern is found, and false otherwise.
ereg_replace() The ereg_replace() function searches for string specified by pattern and replaces pattern with
replacement if found.
eregi() The eregi() function searches throughout a string specified by pattern for a string specified by string. The
search is not case sensitive
PHP json_encode: The json_encode() function returns the JSON representation of a value. In other words, it
converts PHP variable (containing array) into JSON.
Syntax: string json_encode ( mixed $value [, int $options = 0 [, int $depth = 512 ]] )
<?php $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr); ?>
PHP json_decode:The json_decode() function decodes the JSON string. In other words, it converts JSON string into
a PHP variable.
Syntax: mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
Ex: <?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json, true)); ?>
AJAX: AJAX is not a programming language.
AJAX just uses a combination of:
• A browser built-in XMLHttpRequest object (to request data from a web server)
• JavaScript and HTML DOM (to display or use the data)
JSON: JSON is a text format for storing and transporting data
• JSON is a lightweight data-interchange format
• JSON is plain text written in JavaScript object notation
JSON is used to send data between computers, JSON is language independent The file type for JSON files is ".json"
Unit-3
Insert data
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "database1";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
if($_POST){
$uname=$_POST['uname'];
$upass=$_POST['upass'];
}
$sql = "INSERT INTO users VALUES ('$uname', '$upass')";
if ($conn->query($sql) == TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
<html>
<Body><form method="post">
uname:- <input type="text" name="uname"><br/>
Password:- <input type="password" name="upass"><BR/>
<input type="submit" name="submit"/>
</form>
</BODY>
</html>

mysqli_connect() function opens a new connection to the MySQL server.


connect_error / mysqli_connect_error() function returns the error description from the last connection error
close() / mysqli_close() function closes a previously opened database connection
errno / mysqli_errno() function returns the last error code for the most recent function call, if any
select_db() / mysqli_select_db() function is used to change the default database for the connection
mysqli_query() function performs a query against a database.
mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both.
Syntax: mysqli_fetch_array(result,resulttype);
The mysqli_num_rows() function returns the number of rows in a result set
mysqli_affected_rows() function returns the number of affected rows in the previous SELECT, INSERT, UPDATE,
REPLACE, or DELETE query.
fetch_assoc() / mysqli_fetch_assoc() function fetches a result row as an associative array. Fieldnames returned
from this function are case-sensitive.
fetch_field() / mysqli_fetch_field() function returns the next field (column) in the result-set, as an object.
fetch_object() / mysqli_fetch_object() function returns the current row of a result-set, as an object. Fieldnames
returned from this function are case-sensitive.
fetch_row() / mysqli_fetch_row() function fetches one row from a result-set and returns it as an enumerated array
mysqli_insert_id() function returns the id (generated with AUTO_INCREMENT) from the last query
mysqli_data_seek() function adjusts the result pointer to an arbitrary row in the result-set
UNIT-4
JQUERY selector:
1 The element Selector :The jQuery element selector selects elements based on the element name.
2 #id selector :uses the id attribute of an HTML tag to find the specific element. An id should be unique within a
page, so you should use the #id selector when you want to find a single, unique element
3.class selector finds elements with a specific class. To find elements with a specific class, write a period character,
followed by the name of the class: $(".test")
jQuery Events All the different visitors' actions that a web page can respond to are called events. An event
represents the precise moment when something happens.
Mouse event: click, dblclick, mouseenter, mouseleave Ex: $("p").dblclick(function(){ $(this).hide(); });
Keyboard Events keypress, keydown , keyup
Form Events: submit, change, focus, blur
Document/Window Events: load,resize, scroll,unload
resize() The resize event occurs when the browser window changes size. The resize() method triggers the resize
event, or attaches a function to run when a resize event occurs
jQuery Effects Hide, Show, Toggle, Slide, Fade, and Animate.
Hide and Show With jQuery, you can hide and show HTML elements with the hide() and show() methods:
Syntax: $(selector).hide(speed,callback); $(selector).show(speed,callback);
fadeIn() The jQuery fadeIn() method is used to fade in a hidden element. Syntax:
$(selector).fadeIn(speed,callback);
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast",
or milliseconds.
fadeOut() The method is used to fade out a visible element.
Syntax: $(selector).fadeOut(speed,callback);
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast",
or milliseconds. The optional callback parameter is a function to be executed after the fading completes.
JQuery methods
• text() - Sets or returns the text content of selected elements
• html() - Sets or returns the content of selected elements (including HTML markup)
• val() - Sets or returns the value of form fields
jQuery addClass()method adds one or more class names to the selected elements. This method does not remove
existing class attributes, it only adds one or more class names to the class attribute. Tip: To add more than one
class, separate the class names with spaces.
Syntax: $(selector).addClass(classname,function(index,currentclass))
Ex: $("button").click(function(){
$("p:first").addClass("intro"); });
removeClass() Method removes one or more class names from the selected elements. Note: If no parameter is
specified, this method will remove ALL class names from the selected elements.
Syntax $(selector).removeClass(classname,function(index,currentclass))
Unit -5What is Inheritance?
Inheritance in OOP = When a class derives from another class.
The child class will inherit all the public and protected properties and methods from the parent class. In addition, it
can have its own properties and methods. Constructor:
An inherited class is defined by using the extends keyword. A constructor allows you to initialize an object's
Example: <?php properties upon creation of the object.
class Fruit { If you create a __construct() function, PHP will
public $name; automatically call this function when you create
public $color; object from a class
public function __construct($name, $color) { A destructor is called when the object is
$this->name = $name; destructed or the script is stopped or exited.
$this->color = $color; If you create a __destruct() function, PHP
} will automatically call this function at the end
public function intro() { of the script
echo "The fruit is {$this->name} and the color is {$this->color}."; ex :function __construct($name, $color) {
} $this->name = $name;
} $this->color = $color;}
// Strawberry is inherited from Fruit function __destruct() {
class Strawberry extends Fruit { echo "The fruit is {$this->name} and the color is {$this->color}."
public function message() { }
echo "I am sweet Strawberry. <br> ";
}
}
$strawberry = new Strawberry("Strawberry", "red");
$strawberry->message();
$strawberry->intro();
?>
Autoloading Classes In order to use class defined in another PHP script, we can incorporate it with include or
require statements. However, PHP's autoloading feature doesn't need such explicit inclusion. Many developers
writing object-oriented applications create one PHP source file per class definition. One of the biggest annoyances
is having to write a long list of needed includes at the beginning of each script (one for each class).
Syntax: spl_autoload_register(function ($class_name)
{ include $class_name . '.php'; });
Class Constants Constants cannot be changed once it is declared. Class constants can be useful if you need to
define some constant data within a class. A class constant is declared inside a class with the const keyword
PHP MYSQL Insert Data:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "database1";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO users (user, password) VALUES ('Param', '123')";
if ($conn->query($sql) == TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}$conn->close(); ?>

You might also like