1. How to set environment variables for a PHP Command line app

    It’s pretty simple really.

    instead of doing this..

    php application.php

    you can then do this 

    export ENVIRONMENT_VAR=test; php application.php

    Getting this variable from within PHP is easy - just do a search for the getenv() function ;)

    UPDATE!

    Ok, this works too, with the added advantage of not setting the variable permanently!

    ENVIRONMENT_VAR=test php application.php

    Note that there are no semi colons between the variable and the php command.

  2. How to test if a string is numeric in PHP

    It’s simple really. You use the trim() command.

    Like so..

    $var = ‘1’;
    if (is_numeric(trim($var))
    {
        echo “it’s a number!”; 

  3. Watir making a splash

    I hope you like my journalistic headline. 

    Anyway Watir (pronounced water) and watir-webdriver are two ruby gems that allow you to test web apps.. 

    From the watir website

    Watir, pronounced water, is an open-source (BSD) family of Ruby libraries for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.

    The whole set of software allows you to programmatically test web applications in all 4 major browsers - IE, Firefox, Chrome and Safari.  You can interact with the DOM and check for the correct changes allowing testing of page interaction and AJAX functions.

    A simple program looks something like this..

    require "rubygems" 
    require "watir-webdriver"

    browser.goto "http://google.com"
    browser.text_field(:name => "q").set "watir"
    browser.button.click
    browser.div(:id => "resultStats").wait_until_present
    browser.title.should == "watir - Google Search"

    Nice and simple!