Home Hardware Networking Programmazione Software Domanda Sistemi
Conoscenza Informatica >> Programmazione >> PHP /MySQL Programmazione >> .

Come creare RSS con PHP

Really Simple Syndication , o RSS , è un formato standard per la distribuzione di informazioni su Internet . Molti siti web forniscono notizie RSS mangimi contenenti o il contenuto che viene aggiornato in tandem con il sito e agli utenti di iscriversi ad un feed per ricevere gli aggiornamenti. A differenza di e-mail , RSS consente agli utenti di decidere quali informazioni desiderano ricevere e un utente può annullare l'iscrizione a un feed in qualsiasi momento . È possibile creare un feed RSS utilizzando il linguaggio di scripting PHP , attraverso la comprensione del formato RSS e la scrittura di output XML che segue il formato . Istruzioni
1

Commenta il formato RSS 2.0 per capire come le informazioni devono essere strutturati in un feed RSS . Creare un nuovo file PHP in un editor o utilizzando il Blocco note.
2

Creare una classe per il canale RSS . Includi titolo, link e descrizione , che sono i campi richiesti RSS . Aggiungi un array per memorizzare gli elementi RSS . Creare la funzione di costruzione per creare una nuova istanza del canale . Ad esempio, digitare : ?

class

RSS_channel {

pubblica $ titolo , $ connessione , $ descrizione ;

public function __ construct ( $ titolo , $ connessione , $ descrizione) {

$ this - > title = $ title ;

$ this-> link = $ link ;

$ questo - > descrizione = $ descrizione ;

$ this-> items = array () ; }


3

Creare un metodo per aggiungere un nuovo elemento alla matrice . Chiamare una classe elemento RSS che si creerà dopo. Ad esempio, digitare :

new_item funzione pubblica ( $ titolo , $ connessione , $ descrizione) {

array_push ( $ this - > oggetti , nuovo ( $ titolo , $ link RSS_item , $ descrizione) ) ; }


4

creare una funzione per emettere il codice XML e RSS informazioni di intestazione per il file RSS . Ad esempio, digitare :

RSS_header funzione pubblica ( ) {

$ r = ' < xml version = "1.0" ? ? > ';

$ R . = ' versione ';
ritorno

$ r ;

}
5

Creare un metodo per l'uscita del canale RSS . Uscita i tag XML e gli elementi di dati per il canale. Chiamare la classe elemento RSS per emettere i tag XML e gli elementi dati di ciascun elemento nel canale. Ad esempio, digitare : .

Uscita funzione pubblica ( ) {

$ r = RSS_header ();

$ r = " " ;

$ r . = " " . $ this-> titolo. " < /title >" . <br> <p> $ r = " <link> " . $ this-> collegamento . " < /link > " ; <br> <p> $ r = " <description> " . . $ this-> descrizione . " < /description >" . <br> <p> foreach ( $ this-> oggetti da $ item) { <br> <p> $ r = $ item- > Output ( ) ; <br> <p > } <br> <p> $ r = " < /channel >" . <br> <p> $ r = " < /rss >" . <br> <p> } <br> <p > } <br> 6 <p> creare la classe elemento RSS con un titolo, link e la descrizione . Creare una funzione di costruzione per creare una nuova istanza della classe . Ad esempio, digitare : <br> classe <p> RSS_item { <br> <p> pubblica $ titolo , $ connessione , $ descrizione ; <br> <p> public function __ construct ( $ titolo , $ connessione , $ descrizione) { <br> <p> $ this-> title = $ title ; <br> <p> $ this-> link = $ link ; <br> <p> $ this-> descrizione = $ descrizione ; <br> <p> } <br> 7 <p> Creare un metodo per produrre i contenuti della voce RSS . Ad esempio, digitare : <br> <p> uscita funzione pubblica ( ) { <br> <p> $ r = " <item> " ; <br> <p> $ r = " <title> " . . $ this-> titolo. " < /title >" . <br> <p> $ r = " <link> " . $ this-> collegamento . " < /link > " ; <br> <p> $ r = " <description> " . . $ this-> descrizione . " < /description > " ; <br> <p> $ r = " </item >" . <br> ritorno <p> $ r ; <br> <p> } <br> <p> } <br> 8 <p> Crea un nuovo canale RSS e aggiungere elementi RSS . Emettere il feed RSS per lo schermo. Ad esempio, digitare : <br> <p> $ rss = new RSS_channel ( "News " , " http://example.com/news " , "Esempio News" , " mer 1 giu 2011 13:02:01 +0000 " , " http://example.com "); <br> <p> $ rss - > new_item ( " rapporto di guadagni " , " http://example.com/earnings " , " guadagni rapporto per Example.com " ) ; <br> <p> $ rss - > new_item ( " Meeting del Capitale " , " http://example.com/shmeeting "," Meeting Announcement della Capitale "); <br> <p> $ rss - > , new_item ( " CEO Speech " , " http://example.com/ceospeech " , "Esempio CEO tiene un discorso " ) ; <br> <p> echo $ rss - > Output ( ) ; <br> <p> ? > <br> <br> <ul class="mhjkhjlj"> <li> <a class='LinkPrevArticle' href='/Programmazione/PHP--MySQL-Programmazione/1184434.html' >Come installare un Sistema di Spedizione UPS VirtueMart </a></li> <li> <a class='LinkNextArticle' href='/Programmazione/PHP--MySQL-Programmazione/1184438.html' >Come Flush Output durante l'elaborazione in PHP </a></li> </ul> <div class="deep"> <div class="guanggadsadswqew"><script language='javascript' src='http://www.354353.com/AD/it3.js'></script></div> <div class="guanggadsadswqew1"></div> </div> <div class="xiangguanleitong"> <div class="vbfdghgjt65f"><h4>Informazioni correlate</h4></div> <ul> <li><a href="/Programmazione/C--C-----Programming/1172536.html" target="_blank">Come per rendere i file in MFC </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1184728.html" target="_blank">Come contare record in PHP MySQL Query </a></li><li><a href="/Programmazione/C--C-----Programming/1171490.html" target="_blank">Come utilizzare il C + + per scrivere un codice per calcolare fattoriali con passanti </a></li><li><a href="/Programmazione/Python-Programming/1187302.html" target="_blank">Come fare Python Attendere un comando QUIT </a></li><li><a href="/Programmazione/C--C-----Programming/1170894.html" target="_blank">Come fare un Bounce oggetto in C # </a></li><li><a href="/Programmazione/Java-Programming/1180752.html" target="_blank">Come usare CVS in Eclipse </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1183116.html" target="_blank">Come passare un ID Sub in PHP </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1184464.html" target="_blank">Come output in formato CSV in MySQL </a></li> </ul> </div> </div> </div> <div class="woshiyouleirog"> <div class="zxtjianasd"> <div class="bidssdfjm3"><h4>Articoli consigliati</h4></div> <div class="dasdcdfurit33"> <ul> <li><a href="/Programmazione/PHP--MySQL-Programmazione/1185560.html" target="_blank">Come collegare Visual Basic per Mysql </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1185522.html" target="_blank">Come nascondere un file di estensione PHP </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1185724.html" target="_blank">Come scaricare un file in PHP </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1183288.html" target="_blank">Come rimuovere un blocco PHP </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1185634.html" target="_blank">Come per includere un file PHP in una pagina HTML </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1186332.html" target="_blank">Come eliminare da un database MySQL </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1184072.html" target="_blank">Come cercare tra due date con PHP e MySQL Code </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1184982.html" target="_blank">Come fare un redirect PHP </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1184356.html" target="_blank">Come creare un sito web PHP MySQL </a></li><li><a href="/Programmazione/PHP--MySQL-Programmazione/1182882.html" target="_blank">Un PHP Suggerire a un amico Tutorial </a></li> </ul> </div> </div> <div class="guanggandgsa32a"> </div> <div class="huosirengs"> <li><a class='childclass' href='/Programmazione/C--C-----Programming/' target="_self">C /C + + Programming</a></li> <li><a class='childclass' href='/Programmazione/Computer-Programming-Languages/' target="_self">Computer Programming Languages</a></li> <li><a class='childclass' href='/Programmazione/Delphi-Programming/' target="_self">Delphi Programming</a></li> <li><a class='childclass' href='/Programmazione/Java-Programming/' target="_self">Java Programming</a></li> <li><a class='childclass' href='/Programmazione/Programmazione-Javascript/' target="_self">Programmazione Javascript</a></li> <li><a class='childclass' href='/Programmazione/PHP--MySQL-Programmazione/' target="_self">PHP /MySQL Programmazione</a></li> <li><a class='childclass' href='/Programmazione/Perl-Programming/' target="_self">Perl Programming</a></li> <li><a class='childclass' href='/Programmazione/Python-Programming/' target="_self">Python Programming</a></li> <li><a class='childclass' href='/Programmazione/rubino-Programmazione/' target="_self">rubino Programmazione</a></li> <li><a class='childclass' href='/Programmazione/Nozioni-di-base-di-Visual-Programming/' target="_self">Nozioni di base di Visual Programming</a></li> </div> </div> </div> <div class="dsadsafa-da"> <p class="sdqwfwe42">  </p> <p class="vbnhg654">Programmazione © www.354353.com</p> <p class="iop8iud"> </p> </div> </div> </body> </html>