Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> PHP Script: Separating News Into Pages
CrazyPensil
post Mar 24 2006, 03:43 PM
Post #1


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 42
Joined: 17-March 06
From: Russia, St.Petersburg
Member No.: 12,058



look. I' ve got such a script to add news:

CODE
if($mess&&$subj) {
        $fp=fopen("news.txt", "a");
        $d=date("d").".".date("m").".".date("Y");
        $c=0;
        if(file_exists("news.txt")&&filesize("news.txt")>0) {
            if($c==0) {
                $news="<nnn>|$subj|$d|$login|$mess\n";
            }
            else {
                $news="<nnn>|$subj|$d|$login|$mess";
            }
        }
        else {
            if($c==0) {
                $news="|$subj|$d|$login|$mess\n";
            }
            else {
                $news="|$subj|$d|$login|$mess";
            }
        }
        fwrite($fp,$news);
        fclose($fp);
        $m="Новость успешно добавлена!";
    }
    elseif(!$mess&&$subj) {
        $m="How about subject?";
    }
    elseif(!$subj&&$mess) {
        $m="How abot message?";
    }
    else {
        $m="Complete the following forms:";
    }


such a one for viewing it:

CODE
<?php
    if(file_exists("news.txt")&&filesize("news.txt")!=0) {
        $fp=fopen("news.txt", "r");
        $newss="";
        while (!feof($fp)) {
            $line = fgets($fp, 4096);
            $newss.=$line;
        }
        fclose($fp);
        $news=explode("<nnn>", $newss);
        $i=0;
        $br="";
        foreach ($news as $n) {
            $p=explode("|", $n);
            if($i>0) {
                $br="<br>";
            }
            print "$br<div class=\"news\">\n<div class=\"newtitle\">&nbsp;$p[1]($p[2]), <font class=\"part\">By $p[3]</div></font>\n<div class=\"newbody\"><pre>$p[4]</pre></div></div>";
            $c+=4;
            $i++;
        }
    }
    else {
         print "<center><div class=\"nonews\">Новостей нет!</div></center>";
         $c++;
    }
?>


how should I upgrade it in such a way that my newbody doesn't resize.
I mean I wana let there be only n chars on each page.

Please, help me with this one!!!

P.S. my style file:

CODE
A:link {
    COLOR: #222222; FONT-FAMILY: Verdana; TEXT-DECORATION: none;
}
A:active {
    COLOR: #222222; FONT-FAMILY: Verdana; TEXT-DECORATION: none;
}
A:visited {
    COLOR: #222222; FONT-FAMILY: Verdana; TEXT-DECORATION: none;
}
A:hover {
    color: #ffee00; FONT-FAMILY: Verdana; TEXT-DECORATION: none;
}
hr {
    height: 1px;
}
body {
    scrollbar-face-color : #4444ff;
    scrollbar-shadow-color : #4444ff;
    scrollbar-highlight-color : #4444ff;
    scrollbar-3dlight-color : #4444ff;
    scrollbar-darkshadow-color : #4444ff;
    scrollbar-track-color : #4444ff;
    scrollbar-arrow-color : #ffee00;
    font-family: verdana;
    color: #ffffff;
    margin-left: 30px;
    margin-right: 30px;
    margin-top: 1px;
    background-color: #808080;
}
.gb {
    margin-left: 100px;
    margin-right: 10px;
}
div.refuse {
    color: red;
    font-weight: bold;
}
div.nonews {
    font-family: verdana;
    margin-left: 3px;
    margin-right: 3px;
    background-color: #256E87;
    border: solid white 1px;
}
div.mess {
    margin-top: 3px;
    margin-bottom: 3px;
    border: solid white 1px;
}
div.news {
    margin-left: 3px;
    margin-top: 3px;
    margin-right: 3px;
    margin-bottom: 3px;
    border: solid white 1px;
}
div.newtitle {
    font-family: verdana;
    background-color: #256E87;
    border-bottom: solid white 1px;
    padding: 2px 3px 1px 4px;
}
div.newbody {
    font-family: verdana;
    font-size: 10pt;
    top: 27px;
    margin-left: 15px;
    padding: 2px;
    overflow: auto;
    background-color #000000;
}
.part {
    color: #faa664;
    font-weight: bold;
}
Table {
    border: solid white 0px;
}
tr {
    border: solid #B9E6F6 1px;
}
td {
    border: solid #B9E6F6 1px;
}
td.h {
    border: solid #B9E6F6 1px;
    color: #1D3A46;
}
input {
    border: solid #B9E6F6 1px;
    background-color: white;
}
Go to the top of the page
 
+Quote Post
Hercco
post Mar 26 2006, 04:09 PM
Post #2


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228



I had just quick glance through your code so I hope I didn't miss anything. I understood your question is how you can limit the printing of content of the variable $p[4] (or an array element....) to certain length? The answer is bloody easy use function substr

CODE


substr($p[4], 0, n);



Where n is the number of characters you want to print.


And it seems your newsfile contains a news item per line. Right? Just make another script for showing a complete news item and pass the correct line number as parameter to it. Then in this new script read this line and show the news. You might wish to do a length checking in the original news file if a link to this full news item should be displayed. So if the news content is shorter than n the link ("more" for example) wouldn't be displayed.


I hope this was what you were after. And have fun coding.smile.gif


Go to the top of the page
 
+Quote Post
sid.calcutta
post Mar 26 2006, 10:08 PM
Post #3


Advanced Member
******

Group: Validating
Posts: 111
Joined: 28-January 06
Member No.: 10,917



QUOTE
how should I upgrade it in such a way that my newbody doesn't resize.

Although I have not tested your code, but I think, due to unwanted resize, your layout is getting distorted. If that be the case, try to use <TABLE> and put all the outputs in <TD> $field_name </TD> tag.
I appreciate that the suggestion I have placed here is a mere hint, and not the actual script, obviously based on the assumption that you are facing a layout related problem.
Regards,
Sid
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Microsoft Enlists Jerry Seinfeld(1)
  2. Good News For Transgaming, Microsoft Loses In Eu(1)
  3. Multiple Versions Of Ie(7)
  4. Are Webspaces Old News, Is Myspace...& Others The New Deal(5)
  5. How To Join Two Pages Togother(3)
  6. User Authentication Session Handling Problems(14)
  7. Cute News Errors!(0)
  8. Any News On Starcraft 2, Or Diablo 3?(15)
  9. Worlds Largest Search Engine Directory(10)
  10. Good News To Programmer, Google Code(0)
  11. Google Apps(7)
  12. How To Limit The Number Of Pages In Ms Word?(6)
  13. Sql Injection Prevention (passing Numerical Data Across Pages).(9)
  14. Site Authentication From Adsense For Crawling Login-protected Pages(0)
  15. About Ie Not Showing Pages That Work In Ff(10)
  1. DS News(6)
  2. Hottest Electronic News(7)
  3. Rss/atom Feed For Php(5)
  4. More Legend Of Zelda: Twilight Princess News(5)
  5. Rss News Feeds(2)
  6. Php/xhtml Pages(3)
  7. Multi-page Pdf From Multiple Svg Pages(1)
  8. Should Hubble Telescope Get Upgrade?(6)
  9. How To Bypass The Disabling Of Right-clicking In Pages.(12)
  10. How Can I Include A File In A Html Page ?(11)
  11. Custom 404 Errorpages : How ?(10)
  12. Good News For Google Earth Users In India!(7)
  13. Anyone Here Any News About MacOS 10.5(2)
  14. Simple PHP News System Problems(1)
  15. News: Messenger Live 8 Coming Out Of Beta(0)


 



- Lo-Fi Version Time is now: 29th August 2008 - 03:28 AM