Read a line from text file in PHP


 

 

 

Reading a specific line from text file

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.

 demo1.php

 states.txt

 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>
 
 
 
 
 

 coding-zon-resdline-textfile-state_info

Comments

Popular posts from this blog

Using javascript pass form variables to iframe src

Creating a new PDF by Merging PDF documents using TCPDF

Import excel file into mysql in PHP