WEB2
WEB2
CODE-
<!DOCTYPE html>
<html>
<head>
<title>Swap Two Variables</title>
</head>
<body>
<h2>Enter two numbers to swap</h2>
<form method="post" action="">
<label for="a">Enter first number (a):</label>
<input type="text" name="a" id="a" required>
<br><br>
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$a = $_POST['a'];
$b = $_POST['b'];
$temp = $a;
$a = $b;
$b = $temp;
OUTPUT:
Q23.Write a PHP program to :
a) Transform a string to all uppercase letters.
b) Transform a string to all lowercase letters.
c) Make a string’s first letter uppercase.
d) Make a string’s first letter lowercase and rest of the letters to
uppercase.
CODE-
<html>
<head><h1>STRING METHODS</h1>
</head>
<body>
<?php
$lowercaseString = strtolower($string);
echo $lowercaseString . "<br>";
$firstLetterUppercase = ucfirst($string);
echo $firstLetterUppercase . "<br>";
$firstLowerRestUpper = lcfirst(strtoupper($string));
echo $firstLowerRestUpper . "<br>";
?>
</body>
</html>
OUTPUT:
Q24.Write a PHP program for showing the use of all the operators in PHP.
CODE:
<?php
// Arithmetic Operators
$a = 10;
$b = 5;
// Assignment Operators
$x = 10;
$x += 5; // $x = $x + 5
echo "x: " . $x . "<br>";
$y = 20;
$y -= 3; // $y = $y - 3
echo "y: " . $y . "<br>";
// Comparison Operators
echo "Is 10 equal to 10? " . ($a == $b) . "<br>";
echo "Is 10 identical to 10? " . ($a === $b) . "<br>";
echo "Is 10 not equal to 5? " . ($a != $b) . "<br>";
echo "Is 10 not identical to 5? " . ($a !== $b) . "<br>";
echo "Is 10 greater than 5? " . ($a > $b) . "<br>";
echo "Is 10 less than 5? " . ($a < $b) . "<br>";
echo "Is 10 greater than or equal to 5? " . ($a >= $b) . "<br>";
echo "Is 10 less than or equal to 5? " . ($a <= $b) . "<br>";
// Logical Operators
$p = true;
$q = false;
OUTPUT:
Q25. Write a PHP program to implement Super global variable.
CODE-
1.$GLOBALS
CODE-
<?php
$x = 300;
$y = 200;
function multiplication(){
$GLOBALS['z'] = $GLOBALS['x'] * $GLOBALS['y'];
}
multiplication();
echo $z;
?>
OUTPUT:
2.$_SERVER
CODE:
<?php
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
echo "<br>"
?>
OUTPUT:
3.$Cookie
CODE-
<?php
$cookie_name = "user";
$cookie_value = "AJAY";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 =
1 day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
OUTPUT:
4.$_SESSION
CODE-
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>
OUTPUT: