Page 1 of 1

viewing latest xml posts

Posted: Sat Nov 06, 2010 10:52 pm
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.

Re: viewing latest xml posts

Posted: Sun Nov 07, 2010 11:42 am
by requinix
Are you running PHP 5?

Re: viewing latest xml posts

Posted: Sun Nov 07, 2010 7:48 pm
by McInfo
I recommend SQLite instead of XML as a substitute for MySQL.

Re: viewing latest xml posts

Posted: Mon Nov 08, 2010 8:43 pm
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?

Re: viewing latest xml posts

Posted: Tue Nov 09, 2010 10:41 am
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'));