A Geek Day with PHP, Magpie RSS, Cron, mail function and Everything Niice
DISCLAIMER: For those who are not interested in PHP, you better not bore yourself with this post.
It was ages ago since I made posted some really geek stuff. I think I had to live up with my blog title, Build that Geek — and so I had to rebuild the geek inside me.

Overview
An hour ago, a brilliant idea was distracting my sleepy brain (it was around 4am). The idea was shining so much that my eyes were blinded by it (my pair of eye was facing the inside of my head). At first, I was hesitant to do it by I eventually gave in.
The idea was to create a PHP program that would notify me thru SMS and email every time a PRC Board Exam result is released. The program would ran every five minutes by means of creating a cron job that would execute it.
The program flow are as follows:
- START
- The program, thru the PHP server would contact an external source requesting information.
- The external source would feed the requested information back to the PHP server.
- The program would parse the data in a PHP-readable format.
- The parsed data will be filtered (non-PRC related stuff would be dropped).
- CONDITIONAL: Was the parsed data previously been sent:
- if yes: END.
- if no, continue.
- The program will notify me regarding the PRC Board Exam result release thru SMS [thru an SMS Gateway] and email [thru PHP's mail function]
- END
The Search for Source of Information

I strolled around the Internet. The most reliable source I could have is the PRC Official Website. I visited the website and tried to search for an RSS or a well-organized XML file. Too bad there weren’t any. I thought of extacting information from the website the dirty way (using eregi, str_replace, and other string manipulation functions) but it was too much for my tired brain.
The next one was Philippine Daily Inquirer’s inquirer.net. I immediately searsuched their site and poof, there’s this XML feed. I thought it was all fine but when I checked it, it was pretty outdated. If I’d use it, the program would defeat the purpose of informing me really fast of the latest news.
Next was ABS-CBN News. In their Public Service area, they served PRC Board Exam result news. They supplied an RSS feed, but sadly it was blank. It contained no information.
The last one who successfully won me was GMANews.tv. I checked their site and they were also serving PRC Board Exam result news. I learned that they publish it on-the-go on their Nation section. Their top stories section had a usable RSS feed, woot. Finally, I’ve got it.
Data Parsing and Extraction
The next thing to do was to extract the data. How could I parse the RSS feed in such a way PHP would understand it well. Since Google is my friend, I tried googling my problem. Google (search engine) introduced to me Magpie RSS, the program I was looking. Just feed an RSS feed to Magpie RSS and it would break the individual feed items into arrays.
Implementation of Magpie RSS to the program was easy since they have posted a simple how-to on their website.
Filtering the Data

Since it was a Nation section feed, not all items on the feed were regarding PRC. There was a need to filter it out. The easiest way that came into my mind was to match either one of the following string “prc” or “professional” to the feed descriptions. If the feed description contained the said strings in a non-case-sensitive way, then retain the information; else drop them. What I used in this part was the eregi function.
Notification and all sorts of stuff
The next thing to worry about was on how to notify me. I also realized that previously sent news did not need to be sent from time to time. For this, I made a MySQL database that would save previously sent information. If the information about to be sent is not on the database, then send it; otherwise, don’t.
The email notification was easy. Gladly, PHP has this easy-to-use mail function. For the SMS notification, I used a free SMS gateway.
Keep it running, indefinitely
Since the program needs to run from time to time, I made a cron entry that would command the server to run it from time-to-time.
Conclusion
The idea was possible. Barely 30 minutes were spent doing it. Source code may be requested by contacting me thru my contact page (accessible in the header and footer).


Conrad Miguel E. Gozalo is a 17-year old guy from General Santos City, Philippines. He is currently taking up his BS Computer Science at the University of the Philippines Diliman. He is a proud Linux user since August 2008. He is also a big fan of Free and Open Source Software. Know more about him on the 
