caine Posted September 5, 2006 Share Posted September 5, 2006 I'm currently working on php news feed, but I have to sort the news according to departments before the display. In my case, I must arranged those news according to department "[xxxx]" following <title> in the http://everling.nierchi.net/mmubulletins.php. The following is my xml parser. Then I have to activate the hyperlink. Wad else can I do in the following code?<?php $URL="http://everling.nierchi.net/mmubulletins.php"; $file = fopen($URL, 'r'); if(!$file) die("Cannot open file."); //read rss feed contents $readfile = fread($file, 1000); $searchfile = eregi("<item>(.*)</item>", $readfile, $array); //place articles in array $article = explode("<item>", $array[0]); $counter = count($article); echo "<table border='1'>"; echo "<th colspan='2'>Lastest News</th>"; //loop to display all bulletinsfor ($i=0; $i<count; $i++){ //fetch titles ereg("<title>(.*)</title>", $article[i], $title); //fetch categories ereg("<category>(.*)</category>", $article[i], $category); //fetch descriptions ereg("<description>(.*)</description>", $article[i], $description); //fetch links ereg("<link>(.*)</link>", $article[i], $link); echo "<tr><td>"; echo $title[1]; echo "</td><td>"; echo "<a href='$link[1]'\>$link[1]</a>"; echo "</td></tr>";} echo "</table>" ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted September 5, 2006 Share Posted September 5, 2006 Save this as "bulletin.xsl"[code]<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <html> <body> <h2>Bulletin</h2> <table border="1"> <tr bgcolor="#CCCCCC"> <th>Category</th> <th>Title</th> <th>Link</th> </tr> <xsl:for-each select="rss/channel/item"> <xsl:sort select="category"/> <tr> <td><xsl:value-of select="category"/></td> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="link"/></td> </tr> </xsl:for-each> </table> </body> </html></xsl:template></xsl:stylesheet>[/code]and run this script[code]<?php $xml = simplexml_load_file('http://everling.nierchi.net/mmubulletins.php'); $xsl = simpleXML_load_file('bulletin.xsl'); $proc = new XsltProcessor(); $proc->importStylesheet($xsl); $newxml = $proc->transformToDoc($xml); print $newxml->saveXML();?>[/code] Quote Link to comment Share on other sites More sharing options...
caine Posted February 8, 2007 Author Share Posted February 8, 2007 How do I add on this subfunction into the xsl and php code?function decode($text){ $text = html_entity_decode($text,ENT_QUOTES); return $text;} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.