java2 Skrevet 6. april 2007 Rapporter Del Skrevet 6. april 2007 Hi for my project i have decided to create a news page where articles are loaded from an xml file. what i have: at the moment my articles are kept in separate xml files and are loaded into html in ascending order. what i want: being news, id like to have the latest articles to be displayed first, and along side this, id also like to be able to keep all my articles in 1 xml file. this is the code i have created thus far: <?php include_once 'includes/common.inc.php'; $handle = opendir($fileDir); while (($file = readdir($handle)) !== FALSE) { if (is_dir($fileDir . $file)) continue; if (!eregi("^news.*\.xml$", $file)) continue; $news = simplexml_load_file($fileDir . $file); $id = htmlentities($news['id']); $title = htmlentities($news->title); echo '<div id="article">'; echo '<div id="article-top">'; echo '<h2>' . ($title) . '</h2>'; echo '<h5>' . htmlentities($news->pubdate) . '</h5>'; echo '</div>'; echo '<p>' . htmlentities($news->body) . '</p>'; echo '<a name="' . ($id) . '" id="' . ($title) . '"></a>'; echo '</div>'; } ?> can anyone help me? any help is appreciated... thx Lenke til kommentar
java2 Skrevet 10. april 2007 Forfatter Rapporter Del Skrevet 10. april 2007 ingen kan xml ?? Hi for my project i have decided to create a news page where articles are loaded from an xml file. what i have: at the moment my articles are kept in separate xml files and are loaded into html in ascending order. what i want: being news, id like to have the latest articles to be displayed first, and along side this, id also like to be able to keep all my articles in 1 xml file. this is the code i have created thus far: <?php include_once 'includes/common.inc.php'; $handle = opendir($fileDir); while (($file = readdir($handle)) !== FALSE) { if (is_dir($fileDir . $file)) continue; if (!eregi("^news.*\.xml$", $file)) continue; $news = simplexml_load_file($fileDir . $file); $id = htmlentities($news['id']); $title = htmlentities($news->title); echo '<div id="article">'; echo '<div id="article-top">'; echo '<h2>' . ($title) . '</h2>'; echo '<h5>' . htmlentities($news->pubdate) . '</h5>'; echo '</div>'; echo '<p>' . htmlentities($news->body) . '</p>'; echo '<a name="' . ($id) . '" id="' . ($title) . '"></a>'; echo '</div>'; } ?> can anyone help me? any help is appreciated... thx 8320057[/snapback] Lenke til kommentar
PHPdude Skrevet 10. april 2007 Rapporter Del Skrevet 10. april 2007 Du ønsker altså å sortere artikler fra en XML-fil etter dato? Sånt har man vel XPath til? Bare å kjøre $news->xpath('SOME QUERY') for å få resultatet. Lenke til kommentar
java2 Skrevet 10. april 2007 Forfatter Rapporter Del Skrevet 10. april 2007 Hei Ja jeg vil sortere den slik at den siste nyheten kommer først. Jeg har denne filen ,ikke Xpath <?php include 'security.inc.php'; include_once '../common.inc.php'; $doc = new DOMDocument(); $root = $doc->createElement('news'); $root = $doc->appendChild($root); $timestamp = date('YmdHis'); do { $id = 'news' . $timestamp++; } while (file_exists($fileDir . $id . '.xml')); $root->setAttribute('id', $id); $author = $doc->createElement('authorid'); $root->appendChild($author); $atext = $doc->createTextNode($_POST['authorid']); $author->appendChild($atext); $cat = $doc->createElement('categoryid'); $root->appendChild($cat); $ctext = $doc->createTextNode($_POST['categoryid']); $cat->appendChild($ctext); $head = $doc->createElement('headline'); $root->appendChild($head); $htext = $doc->createTextNode($_POST['headline']); $head->appendChild($htext); $url = $doc->createElement('url'); $root->appendChild($url); $utext = $doc->createTextNode($_POST['url']); $url->appendChild($utext); $desc = $doc->createElement('description'); $root->appendChild($desc); $dtext = $doc->createTextNode($_POST['description']); $desc->appendChild($dtext); $pub = $doc->createElement('pubdate'); $root->appendChild($pub); $pubtext = $doc->createTextNode(date('Y-m-d')); $pub->appendChild($pubtext); $stat = $doc->createElement('status'); $root->appendChild($stat); $stext = $doc->createTextNode($_POST['status']); $stat->appendChild($stext); $key = $doc->createElement('keywords'); $root->appendChild($key); $ktext = $doc->createTextNode($_POST['keywords']); $key->appendChild($ktext); $filename = $fileDir . $id . '.xml'; $doc->save($filename); header('location: newstool.php'); ?> Du ønsker altså å sortere artikler fra en XML-fil etter dato? Sånt har man vel XPath til?Bare å kjøre $news->xpath('SOME QUERY') for å få resultatet. 8348655[/snapback] Du ønsker altså å sortere artikler fra en XML-fil etter dato? Sånt har man vel XPath til?Bare å kjøre $news->xpath('SOME QUERY') for å få resultatet. 8348655[/snapback] Lenke til kommentar
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå