[go: up one dir, main page]

0% found this document useful (0 votes)
235 views2 pages

PROGRAM-7: Write A PHP Script To Read Data From TXT File and Display It in HTML Table (The File Contains Info in Format Name: Password: Email) - Code

The document describes a PHP script that reads data from a text file containing user information in a name:password:email format and displays it in an HTML table. The script opens the text file, splits each line on colon delimiters, trims whitespace and outputs the name, password and email in separate table cells.

Uploaded by

Harsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
235 views2 pages

PROGRAM-7: Write A PHP Script To Read Data From TXT File and Display It in HTML Table (The File Contains Info in Format Name: Password: Email) - Code

The document describes a PHP script that reads data from a text file containing user information in a name:password:email format and displays it in an HTML table. The script opens the text file, splits each line on colon delimiters, trims whitespace and outputs the name, password and email in separate table cells.

Uploaded by

Harsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM-7: Write a php script to read data from txt file and display it in html

table (the file contains info in format Name: Password: Email ).


CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Display data from txt file</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
}
table {
border-collapse: collapse;
width: 80%;
margin: 20px auto;
background-color: #ffffff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<?php
$filename = 'data.txt';

if (file_exists($filename)) {
$file = fopen($filename, "r");

echo "<table border='1'>";


echo "<tr><th>Name</th><th>Password</th><th>Email</th></tr>";

while (($line = fgets($file)) !== false) {


$parts = explode(':', $line);

if (count($parts) === 3) {
list($name, $password, $email) = $parts;
echo "<tr><td>" . trim($name) . "</td><td>" . trim($password) . "</td><td>" . trim($email) .
"</td></tr>";
}

17
}

echo "</table>";

fclose($file);
} else {
echo "The file $filename does not exist.";
}
?>
</body>
</html>

OUTPUT:

18

You might also like