PHP Manipulating XML with SimpleXML

SimpleXML is a SAX XML parser. It represents an XML document as a hierarchical set of objects and properties where each element is an object and each attribute is an object property.

Access an XML element using SimpleXML

<?xml version='1.0'?>
   <hotel stars="5">
       <name>President Wilson</name>

Save this file as hotel.xml

How to turn off drupal messages

A red error message displaying on your webpage, visible to every visitor is the worst thing you can do to your site. Unfortunately, drupal displays error messages on the screen by default. There are several solutions to this problem.

1. Install disable_messages plugin

The disable messages plugin is only available for drupal 6 and drupal 7.

2. Edit page.tpl file

Remove the following piece of code from your page.tpl file

Counting cells in Excel

Excel provides 4 different functions to count cells: count(), counta(), countblank(), countif()


Counts cells in the range which hold a value. Empty cells and cells containing formulas are not counted.


Counts non-empty cells in the range. Cells containing formulas are counted.


Counts empty cells in the range.


Counts cells in the range which satisfy a condition. In this example, only cells with value less than 10 are counted.

PHP Benchmark Results

Benchmarking is the process of evaluating existing processes and identifying best practices. For example, there are three ways to loop through an array, we would test each method and identify the best performing method. In terms of code, this very often means identifying methods that would be least expensive in terms of CPU time and memory consumption.

Following is a simple benchmark script. It compares while loop with for loop.

Escaping single quotes inside single quotes in bash

In bash, you can use the backslash character ("\") to escape any character. However, if a single quote is inside single quotes, it cannot be escaped with a backslash character. For example:

alias ycd='some_command'

works fine but

alias ycd='command -option 'something''
alias ycd='command -option \'something\''

both of the above return errors.

A trick around this problem is to use both quotes i.e. use double quotes to surround the single quote and single quotes again to surround the single quote.

Changing keyboard on a mac

  1. Click on the Apple logo and select "System Preferences"
  2. Click on "International" icon on "System Preferences" window.
  3. Click on "Input Menu"
  4. Make sure that "Show input menu in menu bar" is checked.
  5. Make sure the "Keyboard Viewer" is set to viewable.
  6. Select the languages you desire
  7. Close the window
  8. Use the flag icon on the top left to set the keyboard layout