sitenews page ?

Hi,
I like to do a simple site news page like this NameBright - Domain Expired
what wood be the best way to do it to make it easy to update
Thanks

In rough terms… the script reads a txt file and parses the info backwards so that the newest entry is at the top of the list.

The format for the txt file is a bit weird, but for me at the time it worked. I would use a much easier to maintain format now. To give a timeframe of when this was written, this was up and running before I gave Tom the a copy of my current weather site template that he eventually turned into what was the CarterLake templates. I don’t think the news code got into the templates but similar code for the Weather FAQ at the bottom of pages did.

I’m not going to bother releasing it as it is some real nasty code and would be too hard to explain and attempt to support. It would be easier to just rewrite it using current programming skills or perhaps someone has time to take a stab at it.

It works by reading a text file that which contains some HTML code in it with a Delimiter of ::: at the end of each entry. I use ::: a lot in my code as it is very unique and some other delimiters are used in the text itself.

The text file is updated (normally using Ultra Edit using its FTP/SSH browser) and as soon as it is saved the next vistor sees the newest article which is at the bottom of the text file, show at the top of the news screen.

An entry looks like:

`>TITLE OF THE ITEM - 12/10/2008

More details of the news article, perhaps a link included like
Some Link:::`

Like I said weird. Gross might be a better term. The > at the beginning is closing a span tag which creates the title bar effect in CSS. But I would change that a lot in a new version. Even the CSS uses is old and could be done a lot better.

A better format would be something like:

`

Title of the news entry 2008-12-10 description of the news event, link etc... `

Then just parse the info into an array, reverse it and output it with CSS so you can make it pretty.

Lots of us are using the wordpress blog addon for site news.

I see you have it installed. Do you not like it?

Hi Mike,
wordpress is over kill for what i am looking for i just went a basic an easy to update page Beau

I setup a Blogger account with Google and just have it publish to my site and call it as an include.
http://jaxweather.net/WeatherLog/

Haven’t updated it in a while… sigh

-Bob

Hi Kevin
I understand using th :::
but how wood you parse this?

Title of the news entry 2008-12-10 description of the news event, link etc... Beau

by using the simplexml function which can read a XML file format.

what did i do wrong

<?php $news = simplexml_load_file('news.xml'); foreach ($news->news as $value) { print $value; } ?>

beau

To start with where is your news.xml?

Hi Mike, forgot to post

1Title of the news entry 2008-12-10 description of the news event, link etc... 2Title of the news entry 2008-12-10 description of the news event, link etc...

it is in news.xml

That is not valid xml
missing doc type headers

The simplexml function really doesn’t need the doctype headers for testing you can do without.

Datafile:

<news>
    <item>
        <title>1Title of the news entry</title>
        <date>2008-12-10</date>
        <desc>description of the news event, link etc... </desc>
    </item>
    <item>
        <title>2Title of the news entry</title>
        <date>2008-12-10</date>
        <desc>description of the news event, link etc... </desc>
    </item>
</news>

PHP Script:

<?php
   $news = simplexml_load_file('news.xml');

	echo "<pre>";
   foreach ($news->item as $value) {
   		print_r($value);
   }
?>

Should get your started.

Output would look like:

`SimpleXMLElement Object
(
[title] => 1Title of the news entry
[date] => 2008-12-10
[desc] => description of the news event, link etc…
)

SimpleXMLElement Object

(
[title] => 2Title of the news entry
[date] => 2008-12-10
[desc] => description of the news event, link etc…
)`

hi Mike,
http://www.n9mfk.com/newsxml.php

the hole file did not make the last post

<?xml version="1.0" encoding="utf-8"?>

<rdf:RDF
xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#
xmlns=“RDF Site Summary (RSS) 1.0”> http://www.n9mfk.com/newsxml.php

1Title of the news entry 2008-12-10 description of the news event, link etc... 2Title of the news entry 2008-12-10 description of the news event, link etc... Beau

The following shows how you could use the variables you got.

<?php
   $news = simplexml_load_file('news.xml');

    echo "<pre>";
   foreach ($news->item as $value) {
        echo 'Title: ' . $value->title . '
';
        echo 'Date: ' . $value->date . '
';
        echo 'Desc: ' . $value->desc . '
 
';
   }
?>

Which would output (using the same data file above):

`[color=brown]Title: 1Title of the news entry
Date: 2008-12-10
Desc: description of the news event, link etc…

Title: 2Title of the news entry
Date: 2008-12-10
Desc: description of the news event, link etc…[/color] `

Source of test data:
http://www.tnetweather.com/test/news.xml

With
this an this

<?php $news = simplexml_load_file('news.xml'); echo "
";
   foreach ($news->item as $value) {
   		print_r($value);
   }

?>

  1Title of the news entry
  2008-12-10
  description of the news event, link etc... 


  2Title of the news entry
  2008-12-10
  description of the news event, link etc... 

i get 

Warning: simplexml_load_file() [function.simplexml-load-file]: news.xml:6: parser error : Extra content at the end of the document in /virtual/users/e15744-16642/web/newsxml.php on line 53

Warning: simplexml_load_file() [function.simplexml-load-file]: in /virtual/users/e15744-16642/web/newsxml.php on line 53

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /virtual/users/e15744-16642/web/newsxml.php on line 53

That is because your XML is not in a valid format.

You have nested elements but no outside constraining element (Wrong terminology I’m sure).

Look at my example above… which has the structure of…

`

… data

... next data `

Not sure how to explain it, but you can’t have repeating ouside elements. Just one. In this case between the outside element you can have multiple

If you load your data xml file in a browser by itself you will get an error.

Again, I’m using the wrong terminology … but the format of your data is the issue.

BTW… I’m in chat if you have questions… (Chat tab at the top of the forum)… I’m just messing around waiting for the “game” to start at 6 something…

Very basic crude code…
http://www.tnetweather.com/test/news.phps

Using xml data file:
http://www.tnetweather.com/test/news.xml

Results in:
http://www.tnetweather.com/test/news.php

Hi Kevin can you show me how to sort it in reverse

Test body { color: black; font-family: verdana; background-color: black; } #news table { color: white; background-color: black; width: 90%;} #news .date { vertical-align: top; color: cyan; font-size: 80%; padding-left: 10px; padding-right: 10px; border: 1px solid white;} #news .title { vertical-align: top; color: red; font-weight: bold; padding-left: 10px; padding-right: 10px; border: 1px solid white;} #news .desc { font-weight: normal; font-size: 90%; color: white;} <?php $news = simplexml_load_file('news.xml'); $news= array_reverse($news); echo '
'; foreach ($news->item as $value) { echo ''; } echo '
' . $value->date . ' ' . $value->title . '
' . $value->desc . '
'; ?> you can see what i tried Beau

Can’t sort the Xml data since it won’t sort anything… If you look at my test page

http://www.tnetweather.com/test/news.phps

You can see that the first thing I am doing now is storeing the data into an array with the date as the first segment since that is what we will be sorting on.

   $news = simplexml_load_file('news.xml');

   // Place the data into an array... 
   $data = array();
   $newscnt = 0;
   foreach($news->item as $value) {
        $data[$newscnt][0] = $value->date;
        $data[$newscnt][1] = $value->title;
        $data[$newscnt][2] = $value->desc;
        $newscnt++;
    }

Now you can sort the data since the date is the first element in each array set.

$display = array_reverse ($data);

Then you can display the data using the sorted array…

    echo '<div align="center"><table>';
    foreach($dsiplay as $key ) {
        echo '<tr><td class="date">' . $key[0] . '</td>';
        echo '<td class="title">' . $key[1] . '
';
        echo '<div class="desc">' . $key[2] . '</div></td></tr>';
   }
   echo '</table></div> 
';

I’m actually using a function to display the data in the test script so that I can output the data in either direction.