Triple 7 Racing

Increase font size  Decrease font size  Default font size  Skip to content

Welcome @ Triple 7 Racing

We are an online racing team with the main focus on the online racing simulation Live for Speed. You'll find here information about our history, our drivers, our cars and much more. We invite you to have a look at our news, forums and galleries. Or just drop a line in our shoutbox. 


 

Login Form

Welcome, Guest. Please login or register.
May 22, 2012, 08:44:12 pm
Username: Password:
Login with username, password and session length

Forgot your password?

T7R Shoutbox

Latest Message: 1 month, 2 weeks ago
  • 09:54 three_jump : bunny happy easter everyone icon_albino
  • 16:27 BBO : bunny dog bunny
  • 13:31 P1LOT : Urgh. I've eaten so much chocolate I've probably made myself diabetic
  • 09:52 BBO : mrgreen
  • 13:48 three_jump : related: «link»
  • 12:33 BBO : Squishee hmmm happy2
  • 11:28 BBO : sign19 sign17
  • 18:28 Tomas Linnet : offtheair
  • 12:29 BBO : pompom
Please Login to shout..
Forum
Triple 7 Racing  |  General  |  Guides & Help  |  Some PHP stuff « previous next »
Pages: [1]
Author Topic: Some PHP stuff  (Read 3093 times)
three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« on: March 19, 2007, 09:57:40 pm »

right, here is what I want / need to do:
I'm doing some simple kind of a news system atm and due having no sql at the webspace it has to be a bit "simple" (but also because of I know shit about sql databases and stuff Smiley).
Anyway, my plan is to put all the news in different files like year.month.day.txt (070319.txt) and put them all in a directory. Now I want to read that directory, sort all files by date (therefore the filename) and echo them all on the newspage.

The news files look like this:
Code:
18.03.07<;>
News Title<;>
Description<;>
Newstext<;>

And my code  I ended up is:
Code:
$tborder = 0;
$twidth = "100%";
$cssheadline = "headline";
$cssdate = "date";
$csstext = "text";

$cnt = 0;
$pfad = "content/news2/articles/";

function ls($dir)
{
$handle = opendir($dir);
for(;(false !== ($readdir = readdir($handle)));)
{
if($readdir != '.' && $readdir != '..')
{
$path = $dir.'/'.$readdir;
if(is_dir($path))
{ $output[$readdir] = ls($path); }
if(is_file($path) && substr($path,-4) == '.txt')
{ $output[] = $readdir; }
}
}
return isset($output)?$output:false;
closedir($handle);
}

$ary = ls($pfad);
arsort ($ary);


for ( $i = count($ary); $i >= 0; $i--)
{
$string = join("\n",file($pfad.$ary[$i])); // Description, Newstext can be over several lines and contain some html code
$content[$cnt] = explode("<;>", $string);

$len = count($content[$cnt]);
for ($j=0; $j<$len-1; $j++)
{
$content[$cnt][$j];
}

$cnt++;
}

// Augabe news.php
$ncnt = $cnt-1;

for ($i = 1; $i <= $ncnt; $i++)
{
echo "<table border=\"".$tborder."\" width=\"".$twidth."\">\n";
echo "<tr><td class=\"".$cssheadline."\">".$content[$i][1]."</td></tr>";
echo "<tr><td class=\"".$cssdate."\">".$content[$i][0]."</td></tr>";
echo "<tr><td class=\"".$csstext."\"><blockquote>".$content[$i][2]."</blockquote></td></tr>";
echo "</table>\n";
echo "<hr>";
}

Ok, now me being a php noob asks you in hope that you know more than me if there is a better way to do that stuff?
« Last Edit: March 19, 2007, 10:19:47 pm by three_jump » Logged

three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #1 on: March 19, 2007, 10:15:43 pm »

reason for this is also that I wanna do a rss feed at some point later and make me less work with publishing new news Smiley

atm it's just a simple html file Smiley
Logged

Bismarck
Hero Member
*****
Offline Offline

Posts: 713


148015987 bismarck@triple7racing.co.uk
« Reply #2 on: March 20, 2007, 09:54:27 am »

Hi Jan,

maybe a cleaner solution, than this PHP one, using XSLT.

So you have a news.xml, where you enter your news, like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="newssystem.xsl"?>
<newssystem>
<news date="2006-02-28">
<title>Old news</title>
<description>This news is kind of old</description>
<newstext>Hello dear readers,
today i present you a news that will be old in a moment.</newstext>
</news>
<news date="2007-03-20">
<title>Tristan is wearing strange outfits</title>
<description>This news is just undescribable</description>
<newstext>Hello dear readers,
this is a news text ...</newstext>
</news>
<news date="2007-03-14">
<title>News are for newsreaders</title>
<description>This news is still undescribable</description>
<newstext>Hello dear readers,
no news today ...</newstext>
</news>
</newssystem>

and you have a newssystem.xsl, where you can transform the newsitems to a document, like that:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<head>
<title>Jans news page</title>
</head>
<body>
<xsl:apply-templates select="//news">
<xsl:sort select="@date"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>

<xsl:template match="news">
<h2><xsl:value-of select="./title"/></h2>
<p><xsl:value-of select="./newstext"/></p>
</xsl:template>
</xsl:stylesheet>

You just need to call the news.xml in your browser.
This should work in every not to outdated browser and is much more flexible, i think.
« Last Edit: March 20, 2007, 09:56:14 am by Bismarck » Logged

three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #3 on: March 20, 2007, 11:05:42 am »

Would that work when I include that file in a .php file? (As it has to work with include as I'm using some kind of simple template system).

Also I would like to keep the single newsfile structure, as at some point I'll have to copy old news to some kind of archive which is easier by just copying files from one into another dir Smiley
Logged

Bismarck
Hero Member
*****
Offline Offline

Posts: 713


148015987 bismarck@triple7racing.co.uk
« Reply #4 on: March 20, 2007, 11:42:53 am »

Would that work when I include that file in a .php file? (As it has to work with include as I'm using some kind of simple template system).
No idea. If you mean whether it works, if you change the extension from .xml to .php, then yes it works.

Also I would like to keep the single newsfile structure, as at some point I'll have to copy old news to some kind of archive which is easier by just copying files from one into another dir Smiley
With "single newsfile" you think of one file per news?
Else, if you only want to show actual news, you could for instance only show news, that are not older than an amount of specified days. So you can keep that news in one file.
Logged

three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #5 on: March 20, 2007, 11:50:14 am »

Include like in I have one index.php which include the news.php or news.xml. Therefore I would have the html doctype and the xml doctype in the source code and I'm not sure if this would still be valid code or even worse would produce weird stuff...

about the 2nd:
yes, one file per news. With you suggestion I would have a steady growing newsfile which gets loaded everytime but the user doesn't see most of the stuff that is / was loaded. (or am I wrong here?)
« Last Edit: March 20, 2007, 11:52:03 am by three_jump » Logged

three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #6 on: March 21, 2007, 11:35:06 pm »

So far I found not a real solution that is better than my crappy code (with the things I need) so I finished my news system to a stage that it works very well. Smiley  Just needs some code clean up now...
I'm gonna post a link here (for those who are interested in how it looks now) in a few weeks when I have converted all news and the system goes online Smiley
Logged

three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #7 on: March 24, 2007, 03:54:02 pm »

for those who care and don't mind the german texts... here is a short preview of how it will look when I put it online...
Logged

three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #8 on: March 26, 2007, 05:39:40 pm »

haha, can't belive it... rss feed works Smiley
Logged

three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #9 on: April 15, 2007, 01:13:22 am »

here it is....

http://www.radfest-buckow.de/index.php?topic=news
Logged

nikimere
Hero Member
*****
Offline Offline

Posts: 508


« Reply #10 on: April 18, 2007, 12:34:16 pm »

looks well, i haven't looked at the code, did u use JavaScript & css to hide/show the news?
Logged


three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #11 on: April 18, 2007, 04:51:06 pm »

css / js only Smiley but I didn't code the js myself Tongue
Logged

nikimere
Hero Member
*****
Offline Offline

Posts: 508


« Reply #12 on: April 18, 2007, 05:23:59 pm »

cheater Tongue he he!! nah, only messing, good job  Wink
Logged


three_jump
Legend
******
Offline Offline

Posts: 2202


meep meep


« Reply #13 on: October 14, 2007, 04:11:58 pm »

* three_jump digs out old thread...

ok, atm I'm working on some kind of a simple language switch, which is done via a cookie and working well so far.

Now comes the problem:
I'll have to do the site for at least 3 languages and therfore I though it would be cool to have all textstrings I used in just one file. The problem is now that I'm a bit helpless with loading the file so I have the strings (more than 5 in most cases) in all kind of functions without using function($string 1.... ) each time.

I hope anyone has a cool idea to help me out Smiley
Logged

Pages: [1]
« previous next »
    Jump to:  


    Who's Online

    There are currently 31 Guests and 0 Users online

    Who's Racing?

    BBO
    D34N0
    Exodus
    G.I.Joe
    P1LOT
    Sir. Pingo
    SparkyDave
    Three Jump
    Tumz (DK)

    Who's in Teamspeak?

    Copyright © 2006 Triple 7 Racing,  Hosting is sponsored by BneXt IT Solutions Our site is valid CSS Our site is valid XHTML 1.0 Transitional