0% found this document useful (0 votes)
66 views43 pages

Intoduction To PHP: Subject Name: Software Lab-X1 (Web Technologies) Subject Code: Mca 506

PHP is a server-side scripting language commonly used for web development. The document provides an introduction to PHP, including its history and common uses. Key points covered include: - PHP was created in 1994 and is an open source language embedded in HTML for dynamic web content. - It can connect to popular databases like MySQL and is used to manage forms, files, sessions, and build e-commerce sites. - PHP code is executed server-side and has a C-like syntax. It is integrated with many protocols and supports distributed applications.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
66 views43 pages

Intoduction To PHP: Subject Name: Software Lab-X1 (Web Technologies) Subject Code: Mca 506

PHP is a server-side scripting language commonly used for web development. The document provides an introduction to PHP, including its history and common uses. Key points covered include: - PHP was created in 1994 and is an open source language embedded in HTML for dynamic web content. - It can connect to popular databases like MySQL and is used to manage forms, files, sessions, and build e-commerce sites. - PHP code is executed server-side and has a C-like syntax. It is integrated with many protocols and supports distributed applications.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 43

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]

SUBJECT CODE : MCA 506


INTODUCTION TO PHP
PHP started out as a small open source project that evolved as more and more people found out
how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.

PHP is a recursive acronym for "PHP: Hypertext Preprocessor".

PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic
content, databases, session tracking, even build entire e-commerce sites.

It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase,
Informix, and Microsoft SQL Server.

PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix
side. The MySQL server, once started, executes even very complex queries with huge result sets in
record-setting time.

PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added
support for Java and distributed object architectures (COM and CORBA), making n-tier development
a possibility for the first time.

PHP is forgiving: PHP language tries to be as forgiving as possible.

PHP Syntax is C-Like.

Common uses of PHP

PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close
them.

PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data,
return data to the user.

You add, delete, modify elements within your database thru PHP.

Access cookies variables and set cookies.

Using PHP, you can restrict users to access some pages of your website.

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Characteristics of PHP
Five important characteristics make PHP's practical nature possible

Simplicity

Efficiency

Security

Flexibility

Familiarity

ROOT ELEMENT
<BOOK
STORE>

ATTRIBUTE

ELEMENT
CATEGORY

<BOOKS>
<LANGUAGE>

ELEMENT

ELEMENT

AUTHOR
TITLE

W.STALLING

PHP

UNIV.ROLL NO: 1504179

ELEMENT

ELEMENT

YEAR
2003

PRICE

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to print hello word in PHP.


<html>
<body>
<?php
echo " hello";
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to print multiple string.


<html>
<body>
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo " learn to PHP!<br>";
echo "This ", "string ", "was ", "made ",
"with multiple parameters.";
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to declare a variables in php.


<html>
<body>
<?php
$i="sarita";
$$i="sapna";
echo $i;
echo $$i;
echo $sarita;
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to assigning the values of a variable.


<html>
<body>
<?php
$a=7;
$b="hello";
$c=5.6;
echo "it is an integer:$a<br>";
echo "it is a string:$b<br>";
echo "it is float num:$c";
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show a local variables.


<html>
<body>
<?php
function m()
{
$a=10;
echo $a;
$a++;
}
m();
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to create a global variables.


<html>
<body>
<?php
function m($a)
{
echo $a++;
}
$a=10;
m($a);
echo $a;
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show a static variables using function.


<html>
<body>
<?php
function a()
{
static $d=1;
echo $d;
$d++;
}
a();
a();
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show use of reference variable.


<html>
<body>
<?php
function get(&$var)
{
echo $var++;

}
$a=5;
get ($a);
echo "<br>$a";
?>
</body>
</html>

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
Write a program to print sum of two numbers.
<html>
<body>
<?php
$a=10;
$b=100;
$c=$a+$b;
echo "$c";
?>
</body>
</html>

OUTPUT:
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to use a constant.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
define ("ROLLNO","1407152");
echo ROLLNO;
?>
</body>
</html>

OUTPUT:
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to use an if statement.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
$i=2;
$j=3;
if($i<$j)
echo "i is smaller than j";
?>
</body>
</html>

OUTPUT:
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show the if else statement.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
$num=22;
if($num%2==0)
{
echo "number is even";
}
else
{
echo "number is odd";
}
?>
</body>
</html>

OUTPUT:
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to create a for loop statement.


<html>
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<body>
<?php
$a="sarita";
for($a=1;$a<=10;$a++)
{
echo "sarita <br>";
}
?>
</body>
</html>

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to print odd numbers upto 100 using for loop.
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
$num=100;
for($num=1;$num<=100;$num+=2)
{
echo "$num<br>";
}
?>
</body>
</html>

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to print even numbers upto 100 using for loop.
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
$num=100;
for($num=2;$num<=100;$num+=2)
{
echo "$num<br>";
}
?>
</body>
</html>

OUTPUT:
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program using while loop.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
$x = 1;
while($x <= 5)
{
echo "The number is: $x <br>";
$x++;
}
?>
</body>
</html>

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show switch statement.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
$week=7;
switch($week)
{
case 1:
echo "today is monday";
break;
case 2:
echo "today is tuesday";
break;
case 3:
echo "today is wednesday";
break;
case 4:
echo "today is thursday";
break;
case 5:
echo "today is friday";
break;
case 6:
echo "today is saturday";
break;
case 7:
echo "today is sunday";
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
break;
default:
echo "wrong input";
}
?>
</body>
</html>

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show call by value.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
function a($i,$p)
{
$sub=$i-$p;
echo $sub;
}
a(10,20);
?>
</body>
</html>

OUTPUT:
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show call by reference.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
function m(&$a)
{
echo $a++;
}
$n=10;
m($n);
echo $n;
?>
</body>
</html>

OUTPUT:
UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

Write a program to show use of recursive function.


UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506
<html>
<body>
<?php
function recursive($num)
{
echo "$num <br>";
if($num < 50)
{
return recursive($num + 1);
}
}
$startNum=1;
recursive($startNum);
?>
</body>
</html>

OUTPUT:

UNIV.ROLL NO: 1504179

SUBJECT NAME : SOFTWARE LAB-X1[WEB TECHNOLOGIES]


SUBJECT CODE : MCA 506

UNIV.ROLL NO: 1504179

You might also like