3rd Chap of Internet
3rd Chap of Internet
=>
<?php
$filename = "sample.txt";
// Wri ng to a file
file_put_contents($filename, $content);
if (file_exists($filename)) {
$fileContent = file_get_contents($filename);
} else {
// Appending to a file
$fileContent = file_get_contents($filename);
echo "Updated File Content:\n$fileContent\n";
if (file_exists($filename)) {
unlink($filename);
} else {
?>
Write sample program using variables, comparison, condi on checking, itera on using
javascript?
=>// Using Variables
if (number > 5) {
} else {
} else {
console.log(i);
let count = 3;
console.log(count);
count--;
}
console.log("\nList of fruits:");
fruits.forEach((fruit) => {
console.log(fruit);
});
fruits.push("Date");
if (fruits.includes("Banana")) {
} else {
What is event? Write few javascript events. What is the syntax of javascript func on.
=>
JavaScript Events are ac ons or occurrences that happen in the browser. They can be
triggered by various user interac ons or by the browser itself.
A JavaScript func on is defined with the func on keyword, followed by a name, followed by
parentheses ().
Func on names can contain le ers, digits, underscores, and dollar signs (same rules as
variables).
The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)
The code to be executed, by the func on, is placed inside curly brackets: {}
func on name(parameter1, parameter2, parameter3) {
// code to be executed
}
Write javascript func on to implement blank field valida ons of various form elements.
=>
// Func on to validate blank fields
func on validateForm() {
// Get form elements by ID or name
const nameField = document.getElementById("name");
const emailField = document.getElementById("email");
const messageField = document.getElementById("message");
// Set a cookie
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, me() + (86400 * 30), "/"); // Cookie valid for 30
days
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, ini al-scale=1.0">
< tle>Cookie Example</ tle>
</head>
<body>
<?php
// Check if cookies are set
if (isset($_COOKIE[$cookie_name])) {
if (isset($_COOKIE["theme"])) {
echo "<p>Your selected theme is: " . $_COOKIE["theme"] . "</p>";
} else {
echo "<p>No theme preference set.</p>";
}
?>
</body>
</html>