Build a Better Mashup, Get $10K

Thursday, May 8. 2008


Network for GoodVia Jono Smith, Director of Marketing for Network for Good:

Do you know a talented Web strategist or developer interested in coming up with new ways to use the Web for social good? Network for Good & the Case Foundation are sponsoring two $10,000 prizes for Web developers who do just that.

We are challenging developers to mash-up the Network for Good online donation processing API with another Web service to either (a) enhance the online donor experience or (b) revolutionize a nonprofit's ability to fundraise online. As if changing the world was not enough, the two winners will each receive a $10,000 prize.

For more information, you can check out the information page: http://www.netsquared.org/mashup/donatenowchallenge

Seeing as we've built our own little API for the CARMA site, I could envision something that let you look up local power plant emissions and then buy carbon offsets for the typical American's yearly usage.

EULA: If you use this idea and win, you have to buy me a beer with the $10,000. And I get to pick which beer.

Posted by Sandy Smith at 06:42 | Comments (0) | Trackbacks (0)
Bookmark Build a Better Mashup, Get $10K  at del.icio.us Digg Build a Better Mashup, Get $10K Bloglines Build a Better Mashup, Get $10K Technorati Build a Better Mashup, Get $10K Fark this: Build a Better Mashup, Get $10K Bookmark Build a Better Mashup, Get $10K  at YahooMyWeb Bookmark Build a Better Mashup, Get $10K  at Furl.net Bookmark Build a Better Mashup, Get $10K  at reddit.com Bookmark Build a Better Mashup, Get $10K  at blinklist.com Bookmark Build a Better Mashup, Get $10K  at Spurl.net Bookmark Build a Better Mashup, Get $10K  at NewsVine Bookmark Build a Better Mashup, Get $10K  at Simpy.com Bookmark Build a Better Mashup, Get $10K  at blogmarks Bookmark Build a Better Mashup, Get $10K  with wists Bookmark Build a Better Mashup, Get $10K  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Software License Picker

Wednesday, April 30. 2008

Looking at some recent licensing boo-boos, we came up with a nifty little tool to help you find the right license for your open source software. Any feedback would be appreciated, whether involving data correction or other features / categories you'd like added.

Posted by Matt Gibbs in Open Source at 16:30 | Comments (0) | Trackbacks (0)
Bookmark Software License Picker  at del.icio.us Digg Software License Picker Bloglines Software License Picker Technorati Software License Picker Fark this: Software License Picker Bookmark Software License Picker  at YahooMyWeb Bookmark Software License Picker  at Furl.net Bookmark Software License Picker  at reddit.com Bookmark Software License Picker  at blinklist.com Bookmark Software License Picker  at Spurl.net Bookmark Software License Picker  at NewsVine Bookmark Software License Picker  at Simpy.com Bookmark Software License Picker  at blogmarks Bookmark Software License Picker  with wists Bookmark Software License Picker  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Success with MySQL and non-Western Character Sets

Wednesday, April 16. 2008

Languages are tricky, quickly evolving systems, but almost all of them in their current form predate computers. Indeed, most predate typesetting. So there are a ton of writing systems out there that are designed for writing with a trained human hand, and not optimised for discrete mechanical reproduction. Those languages persist, and computers are finally getting powerful enough to reproduce them elegantly. So how do we deal with them?

First, get familiar with Unicode.

Once you've done that, you'll find that regular web applications need a little more to work properly. For instance, what if you want to use full-text indexing on a script that isn't derived from Latin?

Fortunately, MySQL as of version 4.1.1 makes that a lot easier...but there are some tricks.

You'll need to learn about collations in MySQL. It is entirely possible in PHP to set everything you're doing to UTF-8 and have a site that can accept and reproduce lots of different scripts, but the database is storing them as something else. However, you give up a lot. First, your database dumps will be unrecoverable gibberish. Second, functions that depend on MySQL understanding how the underlying data behaves, such as full text indexes, will fail.

MySQL out of the box to have latin1_swedish_ci be the default collation, which I find an extremely odd choice. OK, so they're fighting Amerocentrism, but they're not exactly promoting international standardization. So unless you specify that you want the database storing information as utf8_unicode_ci (which I've found to be the most hassle-free for the widest range of character sets), you'll need to specify that your database and all its tables and rows use the utf8_unicode_ci collation, which will also cause them to store everything as UTF-8.

But wait--you're not done. You'll also need to make sure your connection defaults to UTF-8. That's right, you have to have a clean UTF-8 path through your whole application. Just one place where UTF-8 isn't respected will turn everything to unreadable gibberish or a string of question marks. You can have your application issue 'SET NAMES utf8' for every request. The best option is to make sure you have an environment where you can control the MySQL configuration until they come up with some better defaults.

Once you do this, and providing you do all the things you need to do in HTML and PHP (or the scripting language of your choice) to make them UTF-8-clean as well, you should be able to do all the things you're used to in other languages.

Posted by Sandy Smith in Database Design at 11:59 | Comments (0) | Trackbacks (0)
Bookmark Success with MySQL and non-Western Character Sets  at del.icio.us Digg Success with MySQL and non-Western Character Sets Bloglines Success with MySQL and non-Western Character Sets Technorati Success with MySQL and non-Western Character Sets Fark this: Success with MySQL and non-Western Character Sets Bookmark Success with MySQL and non-Western Character Sets  at YahooMyWeb Bookmark Success with MySQL and non-Western Character Sets  at Furl.net Bookmark Success with MySQL and non-Western Character Sets  at reddit.com Bookmark Success with MySQL and non-Western Character Sets  at blinklist.com Bookmark Success with MySQL and non-Western Character Sets  at Spurl.net Bookmark Success with MySQL and non-Western Character Sets  at NewsVine Bookmark Success with MySQL and non-Western Character Sets  at Simpy.com Bookmark Success with MySQL and non-Western Character Sets  at blogmarks Bookmark Success with MySQL and non-Western Character Sets  with wists Bookmark Success with MySQL and non-Western Character Sets  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Terms of Service - not an April Fool's Joke

Tuesday, April 1. 2008

At least, I hope its not an April Fool's joke. It looks more like someone's lawyers go up to 11. From the Slideshare API Terms of Service.

(iii) use the SlideShare APIs to operate nuclear facilities, life support, or other mission critical application where human life or property may be at stake. You understand that the SlideShare APIs are not designed for such purposes and that their failure in such cases could lead to death, personal injury, or severe property or environmental damage for which SlideShare is not responsible;
Posted by Oscar Merida in APIs at 17:05 | Comment (1) | Trackbacks (0)
Bookmark Terms of Service - not an April Fool's Joke  at del.icio.us Digg Terms of Service - not an April Fool's Joke Bloglines Terms of Service - not an April Fool's Joke Technorati Terms of Service - not an April Fool's Joke Fark this: Terms of Service - not an April Fool's Joke Bookmark Terms of Service - not an April Fool's Joke  at YahooMyWeb Bookmark Terms of Service - not an April Fool's Joke  at Furl.net Bookmark Terms of Service - not an April Fool's Joke  at reddit.com Bookmark Terms of Service - not an April Fool's Joke  at blinklist.com Bookmark Terms of Service - not an April Fool's Joke  at Spurl.net Bookmark Terms of Service - not an April Fool's Joke  at NewsVine Bookmark Terms of Service - not an April Fool's Joke  at Simpy.com Bookmark Terms of Service - not an April Fool's Joke  at blogmarks Bookmark Terms of Service - not an April Fool's Joke  with wists Bookmark Terms of Service - not an April Fool's Joke  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Another set of tips for writing good code.

Friday, March 21. 2008

Jeff Vodel provides tips for writing more comprehensible code, in a very humoruous article. They don't just apply to solo coders, people who inherit or update your code down the line will also thank you. Even though they're written for C programmers, his advice applies to any programming language. For web programmers, #5 should be heeded, as we've learned that the code we run on the server typically contributes only a fraction towards how long users must wait to see your web page. You get more bang for the buck by reducing how much data browsers have to download (file sizes) and how many connection it must make (hits to download css, images, javascript files, etc...).

This means that, if I make a stinky mess, I'm doing it in my own nest. When I'm chasing down a bug at 3 a.m., staring at a nightmare cloud of spaghetti code, and I say, "Dear God, what idiot child of married cousins wrote this garbage?", the answer to that question is "Me."

I've written previously my own set of tips to write readable php code.

Posted by Oscar Merida in Programming at 13:29 | Comments (0) | Trackbacks (0)
Bookmark Another set of tips for writing good code.  at del.icio.us Digg Another set of tips for writing good code. Bloglines Another set of tips for writing good code. Technorati Another set of tips for writing good code. Fark this: Another set of tips for writing good code. Bookmark Another set of tips for writing good code.  at YahooMyWeb Bookmark Another set of tips for writing good code.  at Furl.net Bookmark Another set of tips for writing good code.  at reddit.com Bookmark Another set of tips for writing good code.  at blinklist.com Bookmark Another set of tips for writing good code.  at Spurl.net Bookmark Another set of tips for writing good code.  at NewsVine Bookmark Another set of tips for writing good code.  at Simpy.com Bookmark Another set of tips for writing good code.  at blogmarks Bookmark Another set of tips for writing good code.  with wists Bookmark Another set of tips for writing good code.  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Users will love you if you tame Scope/Feature creep

Friday, March 21. 2008

There is an excellent case study in NY Times on how Zen's ultra simple camcorder the Flip has grabbed 13% of the camcorder market and been the best-selling camcorder on Amazon.com. It did this not by offering every feature and tech acronym buzzword under the sun, but by making it trivially easy to use. David Poque says,

Instead, the Flip has been reduced to the purest essence of video capture. You turn it on, and it's ready to start filming in two seconds. You press the red button once to record (press hard -- it's a little balky) and once to stop. You press Play to review the video, and the Trash button to delete a clip.

There it is: the entire user's manual.

"But Oscar, we don't make camcorders or gadgets. Whats your point?" The success of the Zen lies in getting out of the way of users who want to record a video clip. User's don't need to adjust a million settings, don't have the option of adding special effects, zooming in and out, and so on. They just point and record. Next time you're building out a new web site, section of your web site, or any point where you're asking users to interacts with you - fill out a form, post a comment, make a donation - try to eliminate as much cruft as possible and reduce the interaction to its barest essence. Ideally, and I'm probably a bit of an idealist for writing this, this would mean an email newsletter subscription form that, shocker, has only one field for the user's email address, and no more. Or a donation form that is simply the amount to donate and fields required to process payment. The less hoops you make users jump through, the more users may jump through your hoops.

Posted by Oscar Merida in Social Software at 11:59 | Comments (0) | Trackbacks (0)
Bookmark Users will love you if you tame Scope/Feature creep  at del.icio.us Digg Users will love you if you tame Scope/Feature creep Bloglines Users will love you if you tame Scope/Feature creep Technorati Users will love you if you tame Scope/Feature creep Fark this: Users will love you if you tame Scope/Feature creep Bookmark Users will love you if you tame Scope/Feature creep  at YahooMyWeb Bookmark Users will love you if you tame Scope/Feature creep  at Furl.net Bookmark Users will love you if you tame Scope/Feature creep  at reddit.com Bookmark Users will love you if you tame Scope/Feature creep  at blinklist.com Bookmark Users will love you if you tame Scope/Feature creep  at Spurl.net Bookmark Users will love you if you tame Scope/Feature creep  at NewsVine Bookmark Users will love you if you tame Scope/Feature creep  at Simpy.com Bookmark Users will love you if you tame Scope/Feature creep  at blogmarks Bookmark Users will love you if you tame Scope/Feature creep  with wists Bookmark Users will love you if you tame Scope/Feature creep  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Compare Site Traffic with Google Analytics

Friday, March 21. 2008

Google Analytics releases a new feature two weeks ago, allowing sites to anonymously share data with comparable sites. Benchmarking site traffic has been something we've suggested to clients in the past, and in a few cases have facilitated it on a small scale. But now, you can compare how your blog, online community, association, or non-profit's website compares to peers who also use GA. I'd stress that you're comparing yourself to other peers who use the service and choose to share the data so there is some selection bias, and its up to Google to decide who you are compared with. Still, it makes available data that would otherwise be expensive or impossible to get, and as more sites otp to share their traffic, it can get better. You can learn how to enable this and what you can compare over at googlesystem.

The system is very beta at the moment, and the "Verticals" used to categorize sites are few at the moment. It can still help answer questions like:

  • What are overall traffic patterns in my sector?
  • Is my traffic growth/decline part of an overall traffic growth/decline or unique to my site?
  • What's an "average" site like mine get in Page Visits/Visitors/Bounce Rate/New Vistors, and how do I compare?

Technorati Tags: Google Analytics, nptech

Posted by Oscar Merida in Tools at 11:29 | Comments (0) | Trackbacks (0)
Bookmark Compare Site Traffic with Google Analytics  at del.icio.us Digg Compare Site Traffic with Google Analytics Bloglines Compare Site Traffic with Google Analytics Technorati Compare Site Traffic with Google Analytics Fark this: Compare Site Traffic with Google Analytics Bookmark Compare Site Traffic with Google Analytics  at YahooMyWeb Bookmark Compare Site Traffic with Google Analytics  at Furl.net Bookmark Compare Site Traffic with Google Analytics  at reddit.com Bookmark Compare Site Traffic with Google Analytics  at blinklist.com Bookmark Compare Site Traffic with Google Analytics  at Spurl.net Bookmark Compare Site Traffic with Google Analytics  at NewsVine Bookmark Compare Site Traffic with Google Analytics  at Simpy.com Bookmark Compare Site Traffic with Google Analytics  at blogmarks Bookmark Compare Site Traffic with Google Analytics  with wists Bookmark Compare Site Traffic with Google Analytics  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Think Globally, Act Locally

Wednesday, March 19. 2008

Within just the last several years, concern over climate change has grown significantly.

Interestingly enough, environmentally-focused online user engagement is an idea that remains largely untapped.

For the first time in human history, we are faced with a problem that needs worldwide cooperation to overcome. Scientific studies are showing time and time again that global warming is a very real problem. The effects from this unnatural global acceleration rate are already noticeable, and the media outlets aren't hesitating to scare us as much as possible.

The media, much like the web of the old, broadcasts an impersonal message to a collective whole. It speaks of climate change as if it's an inevitable fate. They speak of this problem as one of tremendous scope, and one that would require more than a goliath effort to undertake. Most people want to make a difference, but are intimidated by the size of the problem, given no direction, and are shown no clear community for which they can participate.

Web2.0 is personal. This "new media" can inspire awe through stories of overcoming obstacles. It can bring about one's inner determination using public disclosure to shock and sicken. It can also simply provide tools to allow users to build their own connections. Interactive media and public disclosure can cause people to want to act, but it's not always enough. Some of us need a personal trainer, not just a nudge. We need to narrow the scope of the problem so we can see exactly what difference we're making at a personal or community level. As this Yahoo CO2 calculator demonstrates, people need to see that even tiny lifestyle changes can make a difference. There needs to be a way of showing progress, a way of clarifying that their "baby steps" are being taken by countless others too -- adding up to an enormous leap forward.

There are some great web projects devoted towards reducing carbon emissions at the individual/community level, but the playing field is still very much open.
Posted by Matt Gibbs in Social Software at 12:12 | Comments (0) | Trackbacks (0)
Bookmark Think Globally, Act Locally  at del.icio.us Digg Think Globally, Act Locally Bloglines Think Globally, Act Locally Technorati Think Globally, Act Locally Fark this: Think Globally, Act Locally Bookmark Think Globally, Act Locally  at YahooMyWeb Bookmark Think Globally, Act Locally  at Furl.net Bookmark Think Globally, Act Locally  at reddit.com Bookmark Think Globally, Act Locally  at blinklist.com Bookmark Think Globally, Act Locally  at Spurl.net Bookmark Think Globally, Act Locally  at NewsVine Bookmark Think Globally, Act Locally  at Simpy.com Bookmark Think Globally, Act Locally  at blogmarks Bookmark Think Globally, Act Locally  with wists Bookmark Think Globally, Act Locally  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Database Optimization & Vertical Partitioning

Tuesday, February 26. 2008

After doing some poking around on how to optimize databases for quicker reads I came across a rather simple approach called Vertical Partitioning.

This approach is rather useful in taking advantage of the Query Cache as you will ultimately reduce the frequency in which the Query Cache is invalidated (blown away!).

Before going further let me explain what the query cache does. It simply stores the text of a SELECT statement along with its result set sent to the client/user upon request. For identical queries the server retrieves the results from the query cache oppose to re-parsing the request and executing the statement resulting in quicker reads.

For tables that contain static (unchanging) and dynamic (changing) data you could take advantage of vertical partitioning. Simply put, instead of creating one table that contains static and dynamic data you can use two tables that contain the static data and another that contains the dynamic data with a foreign key from the static data table. Lets look at the following example!


Un-PartitionedPartitioned

CREATE TABLE Users ( user_id
INT NOT NULL AUTO_INCREMENT,
email VARCHAR(80) NOT NULL,
display_name VARCHAR(50) NOT NULL,
password CHAR(41) NOT NULL,
first_name VARCHAR(25) NOT NULL,
last_name VARCHAR(25) NOT NULL,
address VARCHAR(80) NOT NULL,
city VARCHAR(30) NOT NULL,
province CHAR(2) NOT NULL,
postcode CHAR(7) NOT NULL,
interests TEXT NULL,
bio TEXT NULL,
signature TEXT NULL,
skills TEXT NULL,
PRIMARY KEY (user_id),
UNIQUE INDEX (email))
ENGINE=InnoDB;

CREATE TABLE Users ( user_id
INT NOT NULL AUTO_INCREMENT,
email VARCHAR(80) NOT NULL,
display_name VARCHAR(50) NOT NULL,
password CHAR(41) NOT NULL,
PRIMARY KEY (user_id),
UNIQUE INDEX (email)) ENGINE = InnoDB;

CREATE TABLE UserExtra ( user_id
INT NOT NULL,
first_name VARCHAR(25) NOT NULL,
last_name VARCHAR(25) NOT NULL,
address VARCHAR(80) NOT NULL,
city VARCHAR(30) NOT NULL,
province CHAR(2) NOT NULL,
postcode CHAR(7) NOT NULL,
interests TEXT NULL,
bio TEXT NULL,
signature TEXT NULL,
skills TEXT NULL,
PRIMARY KEY (user_id)) ENGINE=InnoDB;

As a result of the extra user information being partitioned out to its own 'UserExtra' table the frequent updates will not cause the reads for the unchanging data in 'Users' table to slow down keeping the query cache invalidation for 'Users' down to a significant minimum hence consistently faster reads.

Posted by Dan Crowder in Database Design at 11:59 | Comments (0) | Trackbacks (0)
Bookmark Database Optimization & Vertical Partitioning  at del.icio.us Digg Database Optimization & Vertical Partitioning Bloglines Database Optimization & Vertical Partitioning Technorati Database Optimization & Vertical Partitioning Fark this: Database Optimization & Vertical Partitioning Bookmark Database Optimization & Vertical Partitioning  at YahooMyWeb Bookmark Database Optimization & Vertical Partitioning  at Furl.net Bookmark Database Optimization & Vertical Partitioning  at reddit.com Bookmark Database Optimization & Vertical Partitioning  at blinklist.com Bookmark Database Optimization & Vertical Partitioning  at Spurl.net Bookmark Database Optimization & Vertical Partitioning  at NewsVine Bookmark Database Optimization & Vertical Partitioning  at Simpy.com Bookmark Database Optimization & Vertical Partitioning  at blogmarks Bookmark Database Optimization & Vertical Partitioning  with wists Bookmark Database Optimization & Vertical Partitioning  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Using PHP to check SVN commit permissions

Monday, February 18. 2008

Once you've been using Subversion when you and and your colleagues are working on a project, you're bound to find useful ways to exploit Subversion's hook system. We use the sample commit-email.pl script to send all commits to an email list for ad-hoc peer-review. I found and enabled Ian Christian's pre-commit script to check PHP syntax when checking in code.

The latest piece of the puzzle was to restrict commits to a project's branch to a few users, which has been harder to figure out than I expected. The most common script for access control is svnperms, which has a rich syntax for configuring access. Unfortunately, svnperms seems to work best with a repository with the following repository layout:

  • trunk
    • Project1
    • project2
  • branches
    • Project1
    • project2
  • tags
    • Project1
    • project2

Our repository is laid out as:

  • Project1
    • trunk
    • branches
    • tags
  • Project2
    • trunk
    • branches
    • tags

I was trying to restrict access to Project1's stable branch (project1/branches/stable), and this didn't seem to be possible under svnperms, no matter how many regular expressions I tried. Subversion provides another access control script, commit-access-control.pl script, but having been burned by svnperms, I was reluctant to spend too much time trying to configure it and get it to work.

Since hooks are just shell scripts, its easy to write your own, which is what I did in this case. The place to check commit access is before the transaciton is created, in the start-commit hook. Being more comfortable in PHP, I whipped up the following command line script and saved it as check_commit_privs.php

#!/usr/bin/php
<?php
/*
 CHECKS IF A USER CAN COMMIT TO THE REPOSITORY
  Oscar Merida  <omerida@forumone.com>
 */

// SVN passes two arguments, the repository path and user for the commit
$repo_path = $_SERVER['argv'][1];
$commit_user = $_SERVER['argv'][2];

// You can use array to define user groups
$qa_group = array('bob', 'roger', 'amanda'');
$contractors = array('marco', 'dawn', 'bill');

// CONFIGURATION
//
// array key is a path in SVN repository or a regular expression that will match a path.
// value is an array of usernames that can commit to that path
// first path match that limits access will prevent commits.
// This script assumes you only need to lock down certain
// parts of your repository.
$allowed = array(
    // only contractors can commit to widgets project
    '/widgets/' => $contractors,
    // only qa_group can commit to any project's testing branch
    '/.*\/branch\/testing/' => $qa_group,
    // only bill can commit to his project
    '/bills_project/' => array('bill')
);

foreach ($allowed as $regexp => $group)
{
    if (preg_match($regexp, $repo_path)
        && !in_array($commit_user, $group))
    {
        exit(1);
    }
}

To enable this script, create or add a file named 'start-commit' to your repository's hooks/ folder with the following. If there is a file named start-commit.tmpl, copy that as a starting point. You'll also have to make sure that both start-commit and check_commit_privs.php are executable by your SVN users.

REPOS="$1"
USER="$2"
# basic permissions check
/path/to/check_commit_privs.php "$REPOS" "$USER"  || exit 1
Posted by Oscar Merida at 15:03 | Comments (0) | Trackbacks (0)
Bookmark Using PHP to check SVN commit permissions  at del.icio.us Digg Using PHP to check SVN commit permissions Bloglines Using PHP to check SVN commit permissions Technorati Using PHP to check SVN commit permissions Fark this: Using PHP to check SVN commit permissions Bookmark Using PHP to check SVN commit permissions  at YahooMyWeb Bookmark Using PHP to check SVN commit permissions  at Furl.net Bookmark Using PHP to check SVN commit permissions  at reddit.com Bookmark Using PHP to check SVN commit permissions  at blinklist.com Bookmark Using PHP to check SVN commit permissions  at Spurl.net Bookmark Using PHP to check SVN commit permissions  at NewsVine Bookmark Using PHP to check SVN commit permissions  at Simpy.com Bookmark Using PHP to check SVN commit permissions  at blogmarks Bookmark Using PHP to check SVN commit permissions  with wists Bookmark Using PHP to check SVN commit permissions  at Ma.gnolia.com wong it! Bookmark using any bookmark manager!

Lesser Known PHP Tricks

Friday, February 15. 2008

While reading some code, I came across a pleasantly surprising snippet that a coworker had added, and it went something like this:

Calling functions through variables
function display_output()
{
return 'This is the output text!';
}
$variable = 'display_output';
echo $variable();

Result: $variable() = 'This is the output text!';


With closer inspection, this is a pretty cool feature in PHP. It allows you to dynamically call a function by treating a variable like a function. When parentheses are after the variable name, PHP calls the function whose name equals the variable's value. Ex: if $foo = 'bar', then doing $foo() will try calling a function named bar(). Sure, the same result can be achieved using IF loops, but in PHP, it's always good to at least know of the alternatives.

Variable variables
$charlie = 'delta';
$delta = 'oscar';
echo $$charlie;

Result: $$charlie = 'oscar';


My coworker, Oscar, also informed me about "variable variables". These buggers have that extra dollar sign. In the previous example, PHP looks at the value of $charlie, which is 'delta'. It then returns the value of $delta, which is 'oscar'.

Creating variables dynamically
$when = 'future';
$variable_past = 'Welcome to the past';
${'variable_' . $when} = 'Welcome to the ' . $when;

Result: $variable_future is created, and $variable_future = 'Welcome to the future'

This is helpful for when you need to create numerous variables on the fly, such as within a FOR loop. However, it may end up making more sense to create an associative array, depending on how much data you need stored. Ex: $container_array['dynamic_name'] = 'some_value'; Again, this all depends on your given situation.
Posted by Matt Gibbs in Programming at 09:11 | Comments (0) | Trackbacks (0)
Bookmark Lesser Known PHP Tricks  at del.icio.us Digg Lesser Known PHP Tricks Bloglines Lesser Known PHP Tricks Technorati Lesser Known PHP Tricks Fark this: Lesser Known PHP Tricks Bookmark Lesser Known PHP Tricks  at YahooMyWeb Bookmark Lesser Known PHP Tricks  at Furl.net Bookmark Lesser Known PHP Tricks  at reddit.com Bookmark Lesser Known PHP Tricks  at blinklist.com Bookmark Lesser Known PHP Tricks  at Spurl.net Bookmark Lesser Known PHP Tricks  at NewsVine Bookmark Lesser Known PHP Tricks  at Simpy.com Bookmark Lesser Known PHP Tricks  at blogmarks