Академический Документы
Профессиональный Документы
Культура Документы
Submitted To : By :
Dharmesh Santani Kapil Kaushik
Dept . Of Information VII Semester, IT
Technology
EN Technologies Pvt. Ltd.
1.
1. Brief
Brief History
Historyof
of PHP
PHP
2.
2. Getting
Gettingstarted
started
3.
3. Examples
Examples
Brief History of PHP
PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was
initially developed for HTTP usage logging and server-side form generation
in Unix.
PHP 3 (1998) added support for ODBC data sources, multiple platform support,
email protocols (SNMP,IMAP), and new parser written by Zeev Suraski and
Andi Gutmans .
PHP 4 (2000) became an independent component of the web server for added
efficiency. The parser was renamed the Zend Engine. Many security features
were added.
PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML
support using the libxml2 library, SOAP extension for interoperability with
Web Services, SQLite has been bundled with PHP
Brief History of PHP
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Hi, I'm a PHP script!";
?>
</body>
</html>
Why is PHP used?
2. Cross Platform
Runs on almost any Web server on several operating systems.
One of the strongest features is the wide range of supported databases
PHP
Software Free
Copy the code onto your web server and save it as “test.php”.
You should see “Hello World!” displayed.
Notice that the semicolon is used at the end of each line of PHP
code to signify a line break. Like HTML, PHP ignores whitespace
between lines of code. (An HTML equivalent is <BR>)
Getting Started
3. Using conditional statements
Conditional statements are very useful for displaying specific
content to the user. The following example shows how to display
content according to the day of the week.
<?php
$today_dayofweek = date(“w”);
if ($today_dayofweek == 4){
echo “Today is Thursday!”;
}
else{
echo “Today is not Thursday.”;
}
?>
Getting Started
3. Using conditional statements
The if statement checks the value of $today_dayofweek
(which is the numerical day of the week, 0=Sunday… 6=Saturday)
If it is equal to 4 (the numeric representation of Thurs.) it will display
everything within the first { } bracket after the “if()”.
If it is not equal to 4, it will display everything in the second { } bracket
after the “else”.
<?php
$today_dayofweek = date(“w”);
if ($today_dayofweek == 4){
echo “Today is Thursday!”;
}
else{
echo “Today is not Thursday.”;
}
?>
Getting Started
3. Using conditional statements
If we run the script on a Thursday, we should see:
“Today is Thursday”.
On days other than Thursday, we will see:
“Today is not Thursday.”
<?php
$today_dayofweek = date(“w”);
if ($today_dayofweek == 4){
echo “Today is Thursday!”;
}
else{
echo “Today is not Thursday.”;
}
?>
Connection with database
<?php
<?php
//
//Connect
Connectand
andSelect
Selectthe
thedatabase
database
$con=mysql_connect(‘localhost’,‘admin’
$con=mysql_connect(‘localhost’,‘admin’,‘mypassword’);
,‘mypassword’);
if(isset($con))
if(isset($con))
{{
mysql_select_db(‘my_db’);
mysql_select_db(‘my_db’);
}}
else
else
{{
echo”error
echo”errorininthe
theconnection”;
connection”;
}}
?>
?>
The $_GET Function
This built-in method is used to collect values in
a form.
Information sent from a form with the get
method is visible to everyone and has limits on
the amount of information to send.
http://www.customercare.com/welcome.php?fname=Ravi&age=28
The $_POST Function
The built-in $_POST method is used to collect
values in a form.
Information sent from a form with the POST
method is invisible to others and has no limits
on the amount of information to send.
http://www.customercare.com/welcome.php
PHP Session Variables
A SESSION allows you to store user
information on the server for later use (i.e.
username, shopping cart items etc.)
However, the session information is temporary
and is usually deleted very quickly once the
session is terminated.
<?php
Session_start(); //start up your PHP session!
?>
What is a COOKIE?
A cookie is a small file that the server embeds
on the user’s computer.
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
setcookie(“user”,”Alex Porter”,time()+3600);
?>
Examples
PHP is a great way to implement templates on
your website.
<html><head>
<title>MAIET</title>
<link rel="stylesheet" type="text/css" href=“mycssfile.css">
</head>
<body>
<table width=80% height=30>
<tr><td>
<div align=center> Page Title </div>
</td></tr></table>
Examples
Step 2: Universal header and footer in a single file
Next, create a file called footer.php. This file will have all of the footer HTML
code.
This is the basic template that you will use on all of the pages. Make sure you name the
files with a .php extension so that the server will process the PHP code. In this example,
we assume the header and footer files are located in the same directory.
<?php
// header
include(“header.php”);
?>
<?php
// footer
include(“footer.php”);
?>
Examples
Benefits:
- Any changes to header or footer only require editing of a
single file. This reduces the amount of work necessary for
site maintenance and redesign.
- Helps separate the content and design for easier maintenance
Header
Footer
Examples
2. How to output variables using PHP
Echo is the common method in outputting data. Since it
is a language construct, echo doesn’t require parenthesis
like print().
Echo has a shortcut syntax, but it only works with the “short
open tag” configuration enabled on the server. <?= $hits ?>
Examples
3. Other uses with echo()
JEdit http://www.jedit.org/
PHP's creator offers his thoughts on the PHP phenomenon, what has shaped and
motivated the language, and where the PHP movement is heading
http://www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html
Strings:
str_split() - Convert a string to an array
strpbrk() - Search a string for any of a set of characters
substr_compare() - Binary safe optionally case insensitive comparison of two strings from
an offset, up to length characters
Other:
php_check_syntax() - Check the syntax of the specified file
php_strip_whitespace() - Return source with stripped comments and whitespace
THANK YOU.
QUESTIONS…????