PHP RSS Parser – RSS Reader Class for PHP

Just had to create a quick RSS parser for PHP and thought I’d post my solution. The implementation and class follows.

1
2
3
4
5
<?php
$rss = new RSSReader('http://news.google.com/?output=rss');
while ($rss -> hasNext())
	print_r($rss -> next());
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
class RSSReader {
	var $xml = null;
	var $pos = 0;
	var $count = 0;
 
	function __construct($feed_url) {
		$this -> load_url($feed_url);
	}
 
	function load_url($feed_url) {
		$this -> load_string(file_get_contents($feed_url));
	}
 
	function load_string($feed_string) {
		$this -> xml = simplexml_load_string(str_replace('content:encoded', 'content_encoded', $feed_string));
		$this -> pos = 0;
		$this -> count = count($this -> xml -> channel -> item);
	}
 
	function get_title() {
		return $this -> xml -> channel -> title;
	}
 
	function get_link() {
		return $this -> xml -> channel -> link;
	}
 
	function get_pubdate() {
		return $this -> xml -> channel -> pubdate;
	}
 
	function hasNext() {
		return $this -> count > $this -> pos;
	}
 
	function next() {
		$obj = $this -> xml -> channel -> item[$this -> pos++];
		return array(
			'title' => (string) $obj -> title,
			'link' => (string) $obj -> link,
			'description' => (string) $obj -> description,
			'content' => (string) $obj -> content_encoded,
			'pubDate' => strtotime($obj -> pubDate),
		);
	}
}
?>
 
 

Chrome Extensions: History Button, Extensions Button, Downloads Button

I just created some very simple extensions for Chrome shortly after I taught myself how to create extensions.

As I said, they're VERY simple, but I find them useful, so I figured it wouldn't hurt to share them.

Each extension is a simple lightweight extension that adds a shortcut button to your browser for quick access to your history, extensions, or downloads. It either opens a new tab, or switches to the respective tab if you already have it open in a tab you're not using.

You could nearly accomplish the same thing if you made a bookmark, but this assures you won't open multiple tabs and I like to keep some things separate from the bookmarks bar.

Chrome Extensions Button

Chrome History Button

Chrome Downloads Button

 
 

MySQL Select Count Distinct – Counting and Identifying Duplicate Records

Looking for a [relatively] quick way to identify duplicate records in a table and list how many records there are for each duplicate? Look no further.

In my case, I’ve got a table named Searches which tracks queries on one of my sites. I wanted to check the top queries, so I used this SQL statement:

1
2
3
4
5
SELECT COUNT(*) AS repetitions, Query
FROM Searches
GROUP BY Query
HAVING repetitions > 1
ORDER BY repetitions DESC;

There you have it. A simple, effective way to count and label duplicate records.

 
 
 
 

» Recent Comments

  • Afshan: I tweeted your comment o...
  • Diego: When I've said that "is ...
  • Diego: @ Dan I mainly use...

» Meta