Commit f70bd363 authored by Harsh's avatar Harsh

new files

parent 86e55aac
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<style type="text/css" media="screen">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
<body>
<form onsubmit="return Validate();" method="post" enctype="multipart/form-data">
<script type="text/javascript" charset="utf-8" async defer>
function Validate() {
var filename = document.getElementById("up");
var checker = new RegExp("([a-zA-Z0-9\s_\\.\-:])+(.txt)$");
if (!checker.test(filename.value)) {
window.alert("Please upload file with extension '.txt' ");
return false;
}
else
return true;
}
</script>
Upload File: <input type="file" name="upload" id="up" /><br><br>
<input type="submit" name="submit" />
</form>
<?php
$freq = array();
if (isset($_POST["submit"])) {
$f = $_FILES["upload"]["tmp_name"];
if (filesize($f) < 100000)
echo "File size must be greater than 100kB!";
else {
$myFile = fopen($f, "r") or die("Unable to open file");
while (!feof($myFile)) {
$line = fgets($myFile);
$words = str_word_count($line, 1);
foreach ($words as $i => $w) {
$ww = strtolower($w);
if (array_key_exists($ww, $freq))
$freq[$ww]++;
else
$freq[$ww] = 1;
}
}
fclose($myFile);
ksort($freq);
}
}
?>
<?php if (count($freq) > 0): ?>
<br><br>
<table>
<tr>
<th>Words</th>
<th>Frequency</th>
</tr>
<?php foreach ($freq as $key => $value): ?>
<tr>
<td><?php echo $key ?></td>
<td><?php echo $value ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<form action="q5.php" method="post">
Enter array: <input type="text" name="arr" />
<input type="submit" name="submit" />
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Q5</title>
<link rel="stylesheet" href="">
</head>
<body>
<?php
$nums = explode(',', $_POST["arr"]);
$i = 0;
$len = count($nums);
while ($i < $len) {
if ($i == 0)
$i++;
if ($nums[$i] >= $nums[$i - 1])
$i++;
else {
$temp = $nums[$i];
$nums[$i] = $nums[$i - 1];
$nums[$i - 1] = $temp;
$i--;
}
}
for ($j = 0; $j < $len; $j++)
echo $nums[$j] . " ";
?>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment