Blog Not just another WordPress weblog


Remove symbols and punctuations from a string

A very simple function to remove symbols and punctuations from a word.

function replace_symbols($word) {
 $symbols = "~!@#$%^&*()_+=:;?.,";
 for($i=0;$i<strlen($symbols);$i++) {
  $word = str_replace($symbols[$i],'', $word);
 return $word;
} // end of replace_symbols

We can add more symbols to the symbols string.


Building Facebook and Facebook Connect application with Codeigniter – Setup

Developing for Facebook is quite simple and easy if you have the right components.  I used Codeingniter as a base framework for a few Facebook applications and that works pretty well .  I had to do some little tweaking though.

This entry is not about how to build a Facebook application in Codeigniter, its more like the things that I have done to get it going...

I named my controller “fbook”. Very important as the Facebook library is “Facebook” under “application/libraries/”

The “Facebook” PHP client comes with 3 main files,
1. facebook_desktop.php
2. facebookapi_php5_restlib.php
3. facebook.php
We need to create a CI library from these 3 files and the “jsonwrapper”. Create a “facebook-clinet” folder under “application/libraries” folder. Copy paste all the files from the Facebook API library except “facebook.php” to this newly created folder. Rename the “facebook.php” file to “Facebook.php” and place it under “application/libraries” folder. Add the following line to the “Facebook.php” file
include_once 'facebook-client/facebookapi_php5_restlib.php';
This will include the REST library.

This is pretty much the initial setup. You can use the same “Facebook” library to for “Facebook Connect” functionality.


memcache for a dull life

Life is very exciting with real time MySQL queries...but I prefer not to wait for my badly structured query to take more time than it is (static final)necessary...

memcached for all object manipulation...YES

Also, using sub-queries makes life quite dull instead a of JOIN(LEFT/RIGHT/MIDDLE/MESSEDUP any kind...). MySQL should have an "experience lock" on that, unless someone been using sub-queries for 3 years...oh wait, the old version never had sub-queries...well, like always, I am often wrong(but never in doubt).


PHP end tag ?>

A lot of time web programmers make Ajax call to a PHP script to verify content(information). The PHP script usually have a true/false echo, (sometimes 1/0). The PHP script looks something like this

/* do some crazy validation and set $valid value */
if(!$valid) {
 echo "false"
} else {
 echo "true";

This is all good and fun, but SFU when the interpretor reaches ?>! The PHP end tag prints a few CrLfs.

So the Ajax script having the following
will always fail. So trim the Ajax output! Here is the trim function...

function trim(stringToTrim) {
 return stringToTrim.replace(/^\s+|\s+$/g,"");


ISO 3166, ISO 3166-1 & ISO 3166-2

WTF is ISO 3166?

I found a lot of sources for ISO 3166-1 complete MySQL database, but no solid source for ISO 3166-2. So I decided to build my own!

So here is the MySQL dump for these 2 tables.

The "id" field for both table probably is unnecessary as both have ISO 3166-1 alpha-2(I just named it "iso") field.