Jump to content
xisto Community
Sign in to follow this  
CrazyPensil

PHP Script: Separating News Into Pages

Recommended Posts

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

 

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:

 

<?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\"> $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:

 

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;}

Share this post


Link to post
Share on other sites

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

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.:lol:

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.