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 
11 Responses to “A Geek Day with PHP, Magpie RSS, Cron, mail function and Everything Niice” (join them?)
December 23, 2008 at 6:47 am
cool! ur geeeeeeeeeeeeeek!!! rawr!!! give me the source code! hahahahaha
astig!
Jehzeel Laurente’s last blog post..Jehzlau Concepts Evolution
December 23, 2008 at 9:48 am
JuanDerPul toh!! astiig!!
JuanDerPul PINOY’s last blog post..My First Sony Experience is with My SE K750i
December 24, 2008 at 10:41 am
hahhaha…geek ka talaga mikko..matutulog ka na nga lang..madami ka pang naiisip…
Anyway, brilliant idea! Keep it up! Just continue to shine in your field…
exan’s last blog post..My Insights for 3/4 Academic Year
December 24, 2008 at 3:56 pm
Pashare ng source code! Hehe. Ayos!
Merry Christmas, Mikko!
Yehey, nasa blogroll na ako (alone)
December 25, 2008 at 3:09 am
It’s all Greek to me. I’m more interested in attracting 154K subscribers like you do. Now that’s something I’d risk losing a thousand or more neurons figuring out. Hehehe…Merry Christmas!
Jan’s last blog post..Merry Christmas To You All
December 25, 2008 at 5:42 am
Hi Jan.
Minultiply ko lang yan ng 1,000. 154 lang talaga yan.
December 25, 2008 at 7:45 am
Ang galing! A very simple and elegant solution to the problem.
All you need to do now is to setup a blog that will automatically post the data and you’ll be giving every PRC board exam results blog / website a run for their Adsense money. Hehe.
Fitz’s last blog post..A Christmas Message For Everyone
December 26, 2008 at 12:56 pm
Happy Holidays!
Interesting Filipino Posts’s last blog post..Why Is The U.S. Military Preparing For Massive Civil Disorder?
December 30, 2008 at 1:45 am
galing naman, go peyups!
first time ko sa blog mo bro.
Tyrone’s last blog post..ABS-CBN Denies Takipsilim – Twilight Movie TV Series Adaptation
April 27, 2009 at 10:50 pm
What free SMS gateway did you use? I have been looking for a free one for use in Ireland, but couldn’t find one…
April 28, 2009 at 3:02 pm
Great Read! Will be back in the future to check out mroe of your posts.
Leave a reply!