PROGRAM
PROGRAM
<!DOCTYPE html>
<html>
<body>
<?php
//Initialize matrix a
$a = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9)
);
<?php
$count = 0;
$num = 2;
$div_count=0;
if (($num%$i)==0)
$div_count++;
if ($div_count<3)
$count=$count+1;
$num=$num+1;
?>
OUTPUT:
PROGRAM:
<?php
// it to email
$email = "[email protected]";
// Validate email
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
else {
?>
OUTPUT:
PROGRAM:
<?php
function word_digit($word) {
$warr = explode(';',$word);
$result = '';
foreach($warr as $value){
switch(trim($value)){
case 'zero':
$result .= '0';
break;
case 'one':
$result .= '1';
break;
case 'two':
$result .= '2';
break;
case 'three':
$result .= '3';
break;
case 'four':
$result .= '4';
break;
case 'five':
$result .= '5';
break;
case 'six':
$result .= '6';
break;
case 'seven':
$result .= '7';
break;
case 'eight':
$result .= '8';
break;
case 'nine':
$result .= '9';
break;
return $result;
echo word_digit("nine;five;three;one;six;eight")."<br>";
echo word_digit("one;five;eight")."\n";
?>
OUTPUT:
PROGRAM:
<?php
// current time
sleep(5);
// wake up
echo date('h:i:s')."\n";
?>
OUTPUT:
PROGRAM:
<?php
// Text to replace
echo $text
?>
OUTPUT:
PROGRAM:
<!DOCTYPE html>
<html>
<body>
<center>
WELCOME TO JCAS
</h1>
<h3>
</h3>
<form method="POST">
Enter a number:
<input type="Submit"
</form>
</center>
</body>
</html>
<?php
if($_POST) {
$num = $_POST["number"];
");
. $num * $i . "</p>
");
?>
OUTPUT:
PROGRAM:
<?php
$num=4;
$factorial=1;
$factorial=$factorial*$x;
?>
OUTPUT:
PROGRAM:
<?php
$file=file('text.txt');
$fp=fopen('new.txt','w');
$read_rev = array_reverse($file);
$count=0;
foreach($read_rev as $dis_line)
print_r($dis_line);
fwrite($fp,$dis_line);
echo"<br/>";
?>
OUTPUT:
PROGRAM:
<html>
<body>
<br>
size="20"><br>
</form>
<?php
$dirname=$_POST['dir'];
$newextension=$_POST['ext'];
$files=scandir($dirname)
; foreach($files as $file)
if (trim($dirname) !=".")
$newfile=$dirname."/".$f
ile; else
$newfile=$file;
echo "<br>";
if (pathinfo ($newfile,PATHINFO_EXTENSION)=="txt")
{
echo "<br>Old File:".$newfile;
$file_woext=substr($newfile,0,strrpos($newfile,"."));
rename($newfile,$file_woext.".".$newextension);
echo"<br>New File:".$file_woext.".".$newextension;
?>
</body>
</html>
OUTPUT
PROGRAM:
<?php
$dirpath=getcwd();
$dirpath.="\*.php";
$files=array();
$files=glob($dirpath);
usort($files,function($
x,$y){
foreach($files as $item){
echo basename($item)."=>Last Modified On".@date('F d,Y,H:i:s',
filemtime($item))."<br/>";
}
?>
OUTPUT:
PROGRAM:
Email.xml
<company>
<employee>
<department>Production</department>
<empname>Raman</empname>
<empid>1000</empid>
<email>[email protected]</email>
</employee>
<employee>
<department>Sales</department>
<empname>Sunil</empname>
<empid>1003</empid>
<email>[email protected]</email>
</employee>
<employee>
<department>Quality Control</department>
<empname>Rani</empname>
<empid>1011</empid>
<email>[email protected]</email>
</employee>
</company>
<?php
are:";
echo"<br>".$emp-
>empid; echo"-
".$emp->email;
}
?>
OUTPUT:
PROGRAM:
<?php
$domdoc=new DOMDocument();
$domdoc->load('tree.xml');
$domdoc->preserveWhiteSpace=false;
$docroot=$domdoc->documentElement;
$name=$domdoc->getElementsByTagName("name")->item(0)-
>childNodes as $child)
.$docroot->childNodes->item(0)->nodeValue;
?>
OUTPUT:
PROGRAM
conn.php
<?php
Sconn=mysqli_connect("localhost","root", "", "basic command");
//Check connection
if (mysqli_connect_errno())
echo "Failed to connect to MySQL:". mysqli_connect_error();
?>
index.php
<!DOCTYPE html>
<html>
<head>
<title>Basic MySQLi Commands</title>
</head>
<body>
<div>
<form method="POST" action="add.php">
<label>Firstname:</label><input type="text" name="firstname">
<label>Lastname:</label><input type="text" name="lastname">
<input type="submit" name="add">
</form>
</div>
<br>
<div>
<table border="1">
<thead>
<th>Firstname</th>
<th>Lastname</th>
<th></th>
</thead>
<tbody>
<?php
include('conn.php');
$query=mysqli_query(Sconn, "select * from "user");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td>
Srow['userid']; ?>">Edit</a>
<a href="edit.php?id=<?php echo
<a href="delete.php?id=<?php echo
$row['userid']; ?>">Delete</a>
</td>
</tr
<?php
?>
</tbody>
</table>
</div>
</body>
</html>
add.php
<?php
include('conn.php');
Sfirstname=$_POST['firstname'];
Slastname=$_POST['lastname'];
mysqli_query($conn, "insert into "user" (firstname, lastname) values ('$firstname',
'$lastname')");
header('location:index.php");
?>
delete.php
<?php
Sid=$_GET['id'];
include('conn.php");
mysqli_query(Sconn, delete from user where userid="Sid");
header('location:index.php");
7>
edit.php
<?php
include('conn.php');
$id=$_GET['id'];
$query=mysqli_query(Sconn, "select * from 'user' where userid="Sid");
$row=mysqli_fetch_array($query);
<!DOCTYPE html>
<html>
<head>
<title>Basic MySQLi Commands</title>
</head>
body>
<h2>Edit</h2>
<form method="POST" action="update.php?id=<?php echo Sid; ?>">
<label>Firstname:</label><input type="text" value="<?php echo $row['firstname']; ?>"
name="firstname">
<label>Lastname:</label><input type="text" value="<?php echo Srow['lastname']; ?>"
name="lastname">
<input type="submit" name="submit">
<a href="index.php">Back</a>
</form>
</body>
</html>
update.php
<?php
include('conn.php');
$id=$_GET['id'];
$firstname=S_POST['firstname'];
$lastname=$_POST['lastname'];
mysqli_query($conn, "update 'user' set firstname='Sfirstname', lastname='$lastname'
where userid="$id");
header('location:index.php');
?>
OUTPUT: