01-01-2010, 03:57 AM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Jan 2010
Posts: 22
Thanks: 2
|
Paginated Flat File DB
I found this old article on this forum, about paginated txt file databases.
I've set up a site that pulls data from a single-dimensional txt file database, but at the moment it's not paginated.
The text file...
Code:
<!-- Comment1 --><div class="class"><a href="http://www.url.com/1" target="_blank"><img src="http://www.url.com/image1.jpg" border="0"></a></div>
<!-- Comment2 --><div class="class"><a href="http://www.url.com/2" target="_blank"><img src="http://www.url.com/image2.jpg" border="0"></a></div>
<!-- Comment3 --><div class="class"><a href="http://www.url.com/3" target="_blank"><img src="http://www.url.com/image3.jpg" border="0"></a></div>
<!-- Comment4 --><div class="class"><a href="http://www.url.com/4" target="_blank"><img src="http://www.url.com/image4.jpg" border="0"></a></div>
...
The PHP code...
PHP Code:
<?php $fp = fopen('flat-file-data.txt','r'); if (!$fp) {echo 'Cant open file.'; exit;}
while (!feof($fp)) { $line = fgets($fp, 2048); list ($field1, $field2) = split ('\|', $line);
echo ''.$field1.''; echo ''.$field2.'';
$fp++; } fclose($fp);
?>
I have set | as the deliminator but my txt files don't contain any deliminators, only line breaks.
Is there a way of using foreach() and explode() to paginate the data?
I tried doing this but it's not quite working. A few of the lines become truncated...
PHP Code:
<?php $file_handle = fopen('flat-file-data.txt', 'r'); if (!$file_handle) {echo 'Cant open file.'; exit;}
while (!feof($file_handle)) {
$line_of_text = fgets($file_handle, 2048); $field = explode('\|', $line_of_text);
echo $field[0]. ' ';
$file_handle++;
} fclose($file_handle);
?>
Any ideas?
Last edited by codefreek : 01-03-2010 at 03:01 PM.
Reason: PHP tags where added.
|
|
|
|