Jump to content

extracted records, export to txt format


Recommended Posts

hi,

i have already extracted address, city, phone in my txt file.

here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UDAC</title>
</head>

<body>

<?php
//$file = file("gin001.txt");
echo $file;
$a = file("gin003.txt");
$state = "SC";
$count = 0;
foreach ($a as $row => $line)

{

//$data[0] = trim(substr($line,  0, 16))."<br />";
//$data[1] = trim(substr($line, 16,125))."<br />";

$data[2] = trim(substr($line,141, 55))."<br />";

$data[3] = trim(substr($line,196, 32))."<br />";

$data[4] = trim(substr($line,228, 14))."<br />";

//$data[5] = trim(substr($line,240,  2))."<br />";
if ($data[2]!= "<br />" or $data[3] != "<br />" or $data[4] != "<br />") $final[] = $data;
$count++;
}

?>

<table width="100%" border="1">
<th>ADDRESS</th><th>CITY</th><th>PHONE</th><th>ZIP CODE</th>
  <tr>
  <?php for($i = 0;$i <=$count; $i++)
{
$data = $final[$i];?>
    <td><?php echo $data[2];?></td>
    <td><?php echo $data[3];?></td>
    <!--<td><?php //echo $state;?></td>-->
    <td><?php echo $data[4];?></td>

</tr><?php } ?> 

</table>

</body>
</html>

the last thing that i will do is to save this to txt file format.

can php save the output to txt file?

 

thanks in advance

???

Link to comment
https://forums.phpfreaks.com/topic/104233-extracted-records-export-to-txt-format/
Share on other sites

Yes. I choose to use sessions, but you can do it any way you want, check the following:

 

session_start();
$result = mysql_query("SELECT * FROM db");
for($i=0;$i< mysql_num_rows($result);$i++)
{
$_SESSION['content'].=mysql_result($result, $i, "text").", ".mysql_result($result, $i, "text2");
}

header("Content-Disposition: attachment; filename=pdexpressimport.txt");
header("Content-type: text/plain");
header("Pragma: no-cache");
header("Expires: 0"); 
print $_SESSION['content'];

 

That will give you the option to download the text file when you visit the page. If you want to write to a file on the server, read the following:

 

http://www.tizag.com/phpT/filewrite.php

 

this code needs db, i will have to make db and tables.

but the thing is i have a lots of txt file to extract records.

so everytime i extract records it will be save to db and the table will be populated with other records.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.