I have a simple script which records search terms and writes them to an external file. I would like to limit this file size.
[B]The Use:
I have a search page where people can search for PDF files. I would like to have a ‘cloud tag’ or list of the most recent terms searched at the bottom of the page.
Here is my script which works beautifully:
[code=php]
<?php
$pattern = “/filetype:(w+)/”; // filteype:(wildcard for word) to grab the file extension along with the word filetype:
if ( $_GET[‘q’] == “” ) {
$term = “”;
} else {
$term = preg_replace(“$pattern”, ”, $_GET[‘q’]); // get rid of the filetype parameter
}
$searched = $term . “, “;
$fopen = fopen(“searched.html”, “a”);
fwrite($fopen, $searched);
fclose($fopen);
?>
The above code grabs the search term when the SERP page is opened, and writes it to a file. I will later use phpInclude to put the contents of that file on the bottom of my search engine page.
The problem is that after a million searches, this file will be huge!
[B]Question:
How can I limit the file size and organize these search terms so that the most recent ones appear on the page?