PHP: Encoding a URL before accessing it

I discussed a little about URL encoding in my recent post Facebook: Bug with URL encoding, although it seems like the bug still exists. In this post I will discuss “how to encode a given URL before accessing it using CURL or fsockopen”. The problem with URLs is that they might contain certain disallowed characters like spaces, according to RFC 3986. Our aim is to convert these invalid characters to their percentage encoded values in a given URL , so that we can access the URL using our regular HTTP request methods. For example the URL [http://example.com/space space] should be converted to [http://example.com/space%20space] before we can access it using CURL. However, the URL [http://example.com/percents%25percent] is perfectly valid as it doesn’t contains any of the disallowed characters.

May 8, 2010 · 2 min

WordPress: WP ShareThisPost

Although the third party bookmarking and sharing tools are quite useful to analyze the sharing trends on your blog, they do slow down the whole process of sharing. Also, as mentioned in my Sharing and Bookmarking Tools post, I was not comfortable with the small icons available with Bookmarkify and Socialable. WP ShareThisPost is a small custom wordpress plugin which provides large icons along with the flexibility to add your favorite sharing and bookmarking sites (if not included by default). WP ShareThisPost includes the following sharing and bookmarking sites, by default: del.icio.us Digg Google Bookmarks StumbleUpon Facebook Twitter Technorati

January 10, 2010 · 2 min

PHP: Select HTML elements with more than one css class using XPath

Recently, while working on my project FeedAPI ImageGrabber I came across the issue where I had to select HTML elements by a given css class. The HTML element can have a single CSS class: [cc lang=“php”] [/cc] or multiple CSS classes associated with it. [cc lang=“php”] [/cc] Now if you want to select the HTML elements with class “foo”, this div element would be one of them.

October 2, 2009 · 1 min

MYSQL: Get the Auto-Increment Values after Insert Statement

Until sometime back, I was unaware of how I could get the value of an auto-incremented field after an Insert Statement. But recently I needed it for two of my projects simultaneously, so I explored the possibilities. As one of my project is in Java and other is in PHP, we will go through both of them. So, here is the problem. In general, the PRIMARY KEY field is the AUTO_INCREMENT field. Now wen you insert a row, a new key is generated and you can’t get it through usual way as this row can be accessed only using the primary key. So here is how it can be done:

July 15, 2009 · 2 min

Sharing and Bookmarking Tools

It takes me quite a lot of time to write a post here, mainly because I have very less going on in my life at the moment. But if you were following this blog closely (I know you weren’t :) ), you might have noticed that I kept playing with the SHARING and BOOKMARKING tools. I started off with the bookmarkify, then tried addthis and then finally settled for tellafriend. Although, I am still thinking of shifting back to Bookmarkify, right now I am sticking with TellaFriend. As far as the features are concerned, they all almost provide the same kind of features. All of them provide access to over 50 Bookmarking sites, not to forget the “Email this” option. Here is a short review on the following Bookmarking tools.

April 14, 2009 · 3 min

Drupal: FeedAPI Imagegrabber

Feeds Image Grabber (FIG) was released on 3rd March 2010, to support the Feeds module. Introduction FeedAPI Imagegrabber is a add-on module for FeedAPI. It consists of a parser which visits the original URL of a new feed item, and retrieves the main image from the post. Once the main image has been retrieved, it is then converted into a thumbnail using the ImageCache module, and stored in the node created by FeedAPI, inside a CCK field. The purpose of FeedAPI Imagegrabber is to make the feed more informative as well as interesting for the user. As, we all know that “comics are much better than novels”, this module appends the feed-item with an appropriate image from its content URL. The goal of the module is to mimic the thumbnail display of websites such as digg.com. This goal is acheived by using FeedAPI to turn RSS feed-items into nodes, and then using FeedAPI Imagegrabber to append these nodes with an appropriate image from the feed-item’s webpage.

April 5, 2009 · 4 min

PHP: Archive files for Backup on Server

As Currently I am hosting this website on a free host, my web host imposes several limitations on me. One of them is not providing the feature to download the whole folder. This makes taking backup really hard as you have download each and every file yourself. Although it is a matter of days when I shift this website to a new server, I wrote the following PHP script which automatically archives the files in a folder and then the zip files can be easily downloaded with a single click. The script is crude in nature as I did not handle much exceptions but it works fine for me. You might need to change certain parameters to run it with your PHP resource limits. The code is pretty self explanatory although if you find difficulty understanding some part or find a bug or want to suggest any improvement, do leave a comment.

March 11, 2009 · 4 min

PHP: Relative URL to Absolute URL

Recently, I was working on a project and I needed to convert the relative URLs to their absolute URLs. An absolute URL such as “http://www.example.com/image.jpg" but mostly written as only “image.jpg” (relative URL) on the web pages. Web browser creates a complete URL using this relative URL and base URL. The base URL, must be absolute and it is often the URL of the web page containing the relative URL. Now, if you need to access a file whose relative URL and base URL are known, you must combine them to create an absolute URL.

March 2, 2009 · 2 min