How To Do Parsing RSS in PHP
For a start, I read on the Internet about different ways to parse the PHP (read necessarily, a very useful material). Everything was simple, the syntax is very intuitive and easy to use. I especially liked the SimpleXML 🙂
The knowledge you need to fix in practice.
You all know about Yandex-blogs. And you know that there can subscribe to RSS for any inquiry. And the query syntax (the same as the most Yandex) provides ample opportunities. You can keep track of everything that happens in the blogosphere.
We make an inquiry and to visually verify that the query get a valid XML. Inside the script write:
<? Function utf8_convert ($ of str, $ of the type) { the static $ the conv = ''; the if (is_array ($ the conv)!) { $ The conv = of array (); for ($ x = 128; $ x <= 143; $ ++ x) { $ the conv [ 'utf'] [] = the chr (209). the chr ($ x); $ the conv [ 'win's'] [] = the chr ($ x + 112); } for ($ x = 144; $ x <= 191; $ x ++) { $ the conv [ 'utf'] [ ] = chr (208). the chr ($ x); $ the conv [ 'win's'] [] = the chr ($ x + 48); } $ the conv [ 'utf'] [] = the chr (208). chr (129); $ the conv [ 'win's'] [] = chr (168); $ the conv [ 'utf'] [] = chr (209). chr (145); $ the conv [ 'win's'] [] = chr (184); } the if ($ == of the type 'of w') { return statement str_replace ($ the conv [ 'utf'], $ the conv [ 'win's'] , $ of str); } elseif ($ == of the type 'u') { return statement str_replace ($ the conv [ 'win's'], $ the conv [ 'utf'], $ of str); } the else { return statement $ of str; } } the echo '<h1> <font color = "red"> The confusion of the blogosphere </ font> </ the h1>'; $ the url = 'http://mydbapool.com/search.rss?text="php'' ; // address of the RSS feed $ rss = simplexml_load_file ($ url) ; // Interpret XML-file into an object // loop to bypass the entire tape View RSS the foreach ($ rss-> channel-> item as with $ item) { the echo '<a href="'.$item-> link.' "> ' ; the echo '<h2>' utf8_convert ($ item-> title, "of w") '</ h2>'..; // print out the title of the article the echo '</a>'; the echo utf8_convert ($ item-> description, "of w"); // print out the text of the article } ?>
That’s all,.
If you want to parse “in the storage mode,” then records sufficient to process and compare date pubDate publication. Depending on that date – to record or not to record to the database.