Skip to main content


Showing posts from 2013

How to create a simple Web Crawler

Web crawlers are used to extract information from web sites for many purposes.

The simple example given here accepts an URL and exposes some functions to query the content of the page.

To check out the source code of this example :

If you are going to make any improvements to this code, I recommend you to follow TDD and use the unit test class in the code.

Step 1 : Create the class, init function and required attributes In this example, xpath is used for querying the given web page. There is an attribute to hold the page url, and another to hold the xpath object of the loaded page.

The init() function initializes the xpath object for the page URL assigned to url attribute.

class Crawler { public $url = false; protected $xpath = false; public function init() { $xmlDoc = new DOMDocument(); @$xmlDoc->loadHTML(file_get_contents($this->url)); $this->xpath = new DOMXPath(@$xmlDoc); } } In the next two ste…

How to create a simple Wordpress plugin

Last year, I was working on some projects related to bloging platforms such as Wordpress, and I became really passionate about Wordpress during that time. Wordpress has become a very popular CMS, although originally it came as a blog publishing platform. One of the main reasons for this popularity may be it's powerful plugin architecture. So, I thought it's better to write a simple tutorial about how to create a simple plugin for Wordpress.

In this tutorial, I am giving the main priority for the simplicity since I need to show how easy to create a plugin for Wordpress. I highly recommend to improve the structure of code if you are going to use this for a complex project.

This simple plugin will show, the head lines of the latest posts in the bottom of each single post page, so that users will be able to navigate to the latest articles without moving back to the home page.

To check out the source code for this example :