Read a line from text file in PHP
Reading a specific line from text file and display it in HTML Page
This blog demonstrates how to read a specific row from a text file and display the details in an HTML page using PHP.
You can find the demo1.php, states.txt files in the previous tutorials.
demo2.php
<html>
<head>
<title>Coding-zon tutorials</title>
</head>
<body bgcolor=""> <center> <br /><br /><br /><br /> <?php print "<br> <h2>State Information</h2><br />";
$file = file('states.txt'); $row=""; if(isset($_POST['submit'])) { $stateID= $_POST['stateID']; //user selects from downdown foreach($file as $row){ $cols= explode(';', $row);
if( $cols[0] == $stateID){ echo "<table border='1'>"; echo "<tr><td>State Name :</td><td> ". $cols[1] ."</td><tr />"; echo "<tr><td>Capital City :</td><td> ". $cols[2] ."</td><tr />"; echo "<tr><td>Population :</td><td> ". $cols[4] ."</td><tr />"; echo "</table>"; }
}
} echo "<br>"; ?> </center> </body> </html>
Comments
Post a Comment