Tag Archives: php

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.
Continue reading

“What is Drupal?”, for newbies

I often come across this question from my friends and peers and most of the time I deflect it by saying “it lets you create your website easily, why don’t you look up on Wikipedia?”. Few days ago, one of my friends pointed me that most of the articles start with “Drupal is a Content Management System(CMS) …” which becomes pretty much confusing when one has no idea about what a CMS is. In this post, I have tried to explain what a CMS is and why we need it and how Drupal stands out among various other available CMSs.

Let us say you need to create a webpage for your website. Ideally, it would mean you create HTML content that will be delivered to someone who requests it through their web browser. Eventually you grow big and decide to add 100 more pages to your website and therefore create 100 more HTML pages. But then you realize that there is a lot of duplicate content. The footer which contains the copyright information is essentially the same on all pages, therefore if you ever need to edit it then it would mean to edit these 101 pages. This will be a lot of redundant work.
Continue reading

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

Continue reading

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:

<div class="foo"></div>

or multiple CSS classes associated with it.

<div class="foo exp tar"></div>

Now if you want to select the HTML elements with class “foo”, this div element would be one of them.
Continue reading

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:
Continue reading

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.
Continue reading