xml in your own page

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
passie
Posts: 14
Joined: Fri 27. Aug 2004, 16:12
Location: Netherlands

xml in your own page

Post by passie »

hi there,

i just started using phpwcms and i already love it :)
anyway here is my way to insert xml in to my page.
i tought i could share it with you guys&girls :)

Code: Select all

<?php
$newsfeed = 'http://some-xml-or-rss-link.xml';

$fp = @fopen($newsfeed, 'r');
while(!feof($fp)){
$row .= @fgets($fp, 4096);
}
@fclose($fp);

if( eregi('<item>(.*)</item>', $row, $rowitem ) ) {
$item = explode('<item>', $rowitem[0]);

for( $i = 0; $i < count($item) - 1; $i++ ) {

  eregi('<title>(.*)</title>', $item[$i+1], $title );
  eregi('<link>(.*)</link>', $item[$i+1], $url );
  eregi('<description>(.*)</description>', $item[$i+1], $description);
  eregi('<title>(.*)</title>', $item[$i+1], $title2 );


$title[1]= substr ($title[1], 0, 25);
echo "<table  cellpadding=0 cellspacing=0><tr>";
echo "<td>";
 echo '<a href="' . $url[1] . '" title="' . $title2[1] . '">' . $title[1] . '</a><br />';
echo "</td></tr>";
echo "</table>";

}
}
?>
i think it explains it self
just make a file with a name like xml.php or something and import with

Code: Select all

{PHP:xml.php}
have fun with it

greetz,

Passie
jmeyknecht
Posts: 112
Joined: Sun 11. Jan 2004, 23:13
Location: Merseburg, Germany
Contact:

Post by jmeyknecht »

well, if there is no xslt processor in your webspace environment, it's a possibility to show the rss content, but you are limited to rss feeds, that have exactly the xml-structure you are "replacing with nothing".

if you have xslt processor in your webspace environment (check phpinfo) then it is better to transform the xml content with xsl-stylesheets. this is the usual way.
and there are advantages: you can create many xsl-stylesheets and transform different rss feeds or other xml files.

watch this: http://www.phpwcms.de/forum/viewtopic.php?t=2752
kelley
Posts: 33
Joined: Thu 13. May 2004, 08:02

Post by kelley »

Hi,

I gave this a try and all I get is a error on the page of

Code: Select all

Parse error: parse error, unexpected T_STRING in /home/content/k/e/l/kelleylaw/html/xml.php on line 15

Any Ideas.

Kelley
jmeyknecht
Posts: 112
Joined: Sun 11. Jan 2004, 23:13
Location: Merseburg, Germany
Contact:

Post by jmeyknecht »

hmmm, a parse error could be appear with any change. hard to say what happened there...

what did you change?

edit: i see, you used the above code. well, probably it's what i tried to explain, if the xml file structure differs from the one the php code is replacing, it will fail... that's why you should use xslt or with php5 you could also use simple-xml functions.
Post Reply