php_practicals
php_practicals
Html:
<html>
<body>
</form>
</body>
</html>
Php
<?php
if(isset($_POST['set']))
$username=$_POST['username'];
}
if(isset($_POST['update']))
$username=$_POST['username'];
if(isset($_POST['delete']))
if(isset($_POST['show']))
if(isset($_COOKIE['user']))
else
?>
2) Session
Html:
<html>
<body>
</form>
</body>
</html>
Php
<?php
session_start();
if(isset($_POST['set']))
$_SESSION['user']=$_POST['username'];
if(isset($_POST['get']))
{
if(isset($_SESSION['user']))
else
if(isset($_POST['destroy']))
session_unset();
session_destroy();
?>
<html>
<body>
</form>
</body>
</html>
Php
<?php
if(empty($_POST['t1']))
else
if(!is_numeric($_POST['mob']))
else
$n=$_POST['user'];
$p="/^[a-z0-9]*$/";
if(!preg_match($p,$n))
else
?>
4) Design a web page using following form controls: a. Text box, b. Radio
button, c. Check box, d. Buttons
Html
<html>
<body>
<label>Gender:</label>
<label>Hobbies:</label>
<input type="submit">
</form></body></html>
Php
<?php
if(isset($_POST['t1']))
if(isset($_POST['gender']))
echo "Gender:".$_POST['gender'];
if(isset($_POST['hobby']))
echo "Hobby:".$_POST['hobby'];
?>
5) Design a web page using following form controls: a. List box, b. Combo box,
c. Hidden field box
Html
<html>
<body>
<label>Your country:</label>
<select name="country">
<option>India</option>
<option>Us</option>
<option>Canada</option></select>
<label>You hobbies:</label>
<option>Singing</option>
<option>drawing</option>
<option>dancing</option>
<option>cooking</option>
</select>
<input type="submit">
</form>
</body>
</html>
Php
<?php
if(isset($_POST["country"])) {
if(isset($_POST["hobby"])) {
if(isset($_POST["user"])) {
?>
6) Introspection
<?php
Trait traitsample
Interface interfacesample
use traitsample;
public $name="saee";
public $age=19;
$obj=new classsample();
echo "<br>";
echo "<br>";
print_r(get_class_methods("classsample"));
echo "<br>";
echo "<br>";
print_r(get_class_vars("classsample"));
echo "<br>";
echo "<br>";
if(class_exists("classsample"))
else
echo "<br>";
echo "<br>";
if(interface_exists("interfacesample"))
else
echo "<br>";
echo "<br>";
if(trait_exists("traitsample"))
else
echo "<br>";
?>
7) Serialization
<?php
echo "Serialization:<br>";
echo $a . "<br>";
$a_un = unserialize($a);
echo "Unserialization:<br>";
print_r($a_un);
?>
8) PDF
<?php
require('fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',20);
$pdf->Output();
?>
9) Array
<?php
$fruits=array("apple","banana","mango");
foreach($fruits as $fruit)
echo $fruit."<br>";
$student=array("name"=>"saee","age"=>19,"city"=>"pune");
foreach($student as $key=>$value)
$students=array(
array("saee",19,"pune"),
array("john",20,"mumbai"),
array("peter",30,"nashik"));
print_r($students);
?>
10) String
<?php
$str="hello php";
$arr=array("blue","red","pink");
echo "<br>";
echo "<br>";
echo "<br>";
echo strpos($str,"php");
echo "<br>";
print_r (str_replace("red","yellow",$arr));
echo "<br>";
echo "<br>";
echo strtolower("HELLO");
echo "<br>";
echo strtoupper("hello");
echo "<br>";
?>
11) For loop
<?php
?>
$num = 1;
$num++;
?>
$num = 5;
do {
$num++;
?>
14) If statement
<?php
$a=10;
if($a==10)
15) If else
<?php
$x = -15;
if ($x > 0)
else
?>
16) Switch
<?php
$day = "Tuesday";
switch($day) {
case "Monday":
break;
case "Tuesday":
break;
case "Wednesday":
break;
default:
?>
17) Operators
<?php
// 1. Arithmetic Operators
$a = 10;
$b = 5;
// 2. Assignment Operators
$c = $a; // = operator
$c += 5; // += operator
// 3. Comparison Operators
echo "Is a not equal to b? " . ($a != $b) . "<br>"; // true (1)
// 4. Logical Operators
$x = true;
$y = false;
echo "x AND y: " . ($x && $y) . "<br>"; // false (empty)
// 5. Increment/Decrement Operators
$num = 3;
// 6. String Operators
$str2 = "World!";
// 7. Array Operators
echo "Are arrays equal? " . ($arr1 == $arr2) . "<br>"; // true (1)
$a = 6; // 0110 in binary
$b = 3; // 0011 in binary
echo "1. AND (&): a & b = " . ($a & $b) . "<br>"; // 0110 & 0011 = 0010 => 2
echo "2. OR (|): a | b = " . ($a | $b) . "<br>"; // 0110 | 0011 = 0111 => 7
echo "3. XOR (^): a ^ b = " . ($a ^ $b) . "<br>"; // 0110 ^ 0011 = 0101 => 5
?>