|
Posted by shimmyshack on 03/04/07 00:57
On 3 Mar, 11:16, onur...@gmail.com wrote:
> Hi there. i need to cache data from a txt file.
> problem : the txt file is too big. it has lots of categories in it. it
> is too slow to show that data in my page. so i want to cache it maybe
> in a txt or xml file in my server. so second time that i need the data
> it won't be too slow. i want to take the data once in a day but show
> several times. the code below is working as well as i need. but it is
> too slow to open every time refresh my page. if any suggestions, thank
> you.
> Güncel : is a category name in the txt file.
> BCList2.txt : data file from another site
>
> here is the code
>
> <?
> if (!$kategori_haber) $kategori_haber = array("Guncel");
> $satir = file("http://www.ntvmsnbc.com/news/BCList2.txt") or die("news
> server is off!");
> for ($x = 0; $x < sizeof($kategori_haber); $x++) {
> for ($i = 0; $i < sizeof($satir); $i++) {
> if (trim($satir[$i]) == "+$kategori_haber[$x]") {
> $bas = $i + 2;
> break;}
> }
>
> for ($i = $bas; $i < sizeof($satir); $i++) {
> if (substr($satir[$i], 0, 1) == "+" || $i == sizeof($satir) - 1) {
> $son = $i;
> break;}
> }
>
> for ($i = $bas; $i < $son; $i++) {
> $yazi = trim($satir[$i]);
> if ($yazi != "-" && !eregi("$kategori_haber[$x] Guncel", $yazi)) {
> $yazi = str_replace("/news/./", "http://www.ntvmsnbc.com/news/",
> $yazi);
> $haber_e = explode("|", $yazi);
> $haber_e[0]=str_replace("http://www.ntvmsnbc.com/news/", "",
> $haber_e[0]);
> echo "·<font face=verdana size=1> <a href=\"http://www.ntvmsnbc.com/news/$haber_e[0]\" target=_blank >$haber_e[1]</a></
> font></br>\n";}
> }
> }
>
> ?>
if you really *must* go the text route - which as Steve says is not
wise, why don't you read through this file once per day and make many
smaller files one per category, and also make them into php arrays.
This way you just have to include the file and output the array.
BCList2.txt -> many categoryfiles
category files->php array files
Guncel.php
<?php
$arrayURLs = array(
' /news/./401673.asp|Erdoðan: 301'i deðiþtirmeye varýz',
' /news/./401477.asp|'Türkiye'den komþularýna saldýrý olmaz'',
);
?>
......
since you only make the txt file once per day, then you must prepare
better your input, before you use it inside your php application.
I'm with Steve though - use MySql it's fast and easy to change.
Navigation:
[Reply to this message]
|