viewing latest xml posts

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
polishvalor
Forum Newbie
Posts: 13
Joined: Sat Nov 06, 2010 10:45 pm

viewing latest xml posts

Post by polishvalor »

i'm creating a blog using php and xml since i currently don't have access to mysql but i want to know how to display latest feeds, maybe 3 or so. and also have a next/previous page to the next/previous 3 posts, if possible without loading whole page just the blog box.

Code: Select all

<?php
$doc = new DOMDocument();
$doc->load( 'blog.xml' );

$blog = $doc->getElementsByTagName( "post" );
$num = $blog->length;
for ($i = $num-1; $i >= 0; $i--){
  $post = $blog->item($i);
  $titles = $post->getElementsByTagName( "title" );
  $title = $titles->item(0)->nodeValue;
  
  $dates= $post->getElementsByTagName( "date" );
  $date= $dates->item(0)->nodeValue;
  
  $contents = $post->getElementsByTagName( "content" );
  $content = $contents->item(0)->nodeValue;
  
  echo "<h1>$title</h1> <d>$date</d> <p>$content</p>";
  }
?>
any help would be greatly appreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: viewing latest xml posts

Post by requinix »

Are you running PHP 5?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: viewing latest xml posts

Post by McInfo »

I recommend SQLite instead of XML as a substitute for MySQL.
polishvalor
Forum Newbie
Posts: 13
Joined: Sat Nov 06, 2010 10:45 pm

Re: viewing latest xml posts

Post by polishvalor »

yes running php5. and i don't think i'll be able to install sqlite on the server i have, rather i don't think i have the access to. this is just a temp solution until i get mysql. is it necessary to parse the code?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: viewing latest xml posts

Post by McInfo »

There is nothing to install.
PHP Manual wrote:The SQLite extension is enabled by default as of PHP 5 [...] , so simply do not disable it and it'll be available.

SQLite is not a client library used to connect to a big database server. SQLite is the server. The SQLite library reads and writes directly to and from the database files on disk.
Try this. If it returns "bool(true)", SQLite exists on your server.

Code: Select all

<?php var_dump(function_exists('sqlite_open'));
Post Reply