Sop3 - PHP Programs
Sop3 - PHP Programs
Theory:
Characteristics of PHP
Simplicity
Efficiency
Security
Flexibility
Familiarity
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?php echo "Hello, World!";?>
</body>
</html>
SOP1 PRACTICAL (PHP) 1
<!DOCTYPE html>
<html>
<head>
<title>Eligible to Vote or not</title>
</head>
<body>
<form action="" method="post"> Enter a
no :
<input type="text" name="t1" placeholder="Enter a number">
<br><input type="submit" name="submit" value="submit">
</form>
<?php
if (isset($_POST['submit'])) {vote();
}
function vote() {
$a = $_POST['t1'];
intval($a); if($a>=18){
echo "You are Eligible for Vote";
}
else{
echo "You are not Eligible for Vote";
}
}
?>
</body>
</html>
OUTPUT:
EXPERIMENT NO 11
Write a PHP function to count the total number of vowels (a,e,i,o,u) from thestring.
Accept a string by using HTML form.
THEORY:
Vowels
The letters A, E, I, O, and U are called vowels. The other letters in thealphabet are
called consonants.
<html>
<body>
<h2>Find Number of Vowels in a String</h2>
<form action="" method="post">
<input type="text" name="string" />
<input type="submit" />
</form>
</body>
</html>
<?php
if($_POST)
{
$string = strtolower($_POST['string']);
$vowels = array('a','e','i','o','u');
$len = strlen($string);
$num = 0;
for($i=0; $i<$len; $i++){
if(in_array($string[$i], $vowels))
{
$num++;
}
}
echo "Number of vowels : ".$num;
}
?>
OUTPUT
EXPERIMENT NO 12
Theory:
PHP Arrays
An array is a special variable, which can hold more than one value at a time.
An array stores multiple values in one single variable:
Indexed arrays :
The index can be assigned automatically (index always starts at 0).
Syntax :
$a = array( value1, value2, ..., value n)
Associative Arrays :
Associative arrays are arrays that use named keys instead of index to identify
record/value. Let us see how to create associative array.
Syntax :
$a = array( key1 => value1, key2 =>value2, ...,key n => value n)
Multi-dimensional Arrays :
A multidimensional array is an array containing one or more arrays. PHP can handle
multiple levels of multidimensional array.
SOP3 PRACTICAL (PHP) 3
<?php
$ml=
array("English"=>"55",
"Hindi"=>"60",
"Maths"=>"70",
"Marathi"=>"85");
echo "<br><br><b>Elements of an array along with their keys:</b>";
echo "<br> <br> Your score ".$ml['English']." in English";
echo "<br> <br> Your score ".$ml['Hindi']." in Hindi";
echo "<br> <br> Your score ".$ml['Maths']." in Maths";
echo "<br> <br> Your score ".$ml['Marathi']." in Marathi";
echo "<br><br><b>Size of an array is :</b>".count($ml);
array_splice($ml,0,1);
echo "<br><br><b>After deleting array is :</b>";
foreach($ml as $x => $x_value)
{
echo "<br><br>Key=". $x. ", Value=" . $x_value;
echo "<br>";
}
?>
Output: