Last night I was working on a home project. I was trying to build a lightbox photo gallery from picasa image gallery feed using google api. When I trying to get all photo list by album name, then I found that, google strips all non alpha-numeric characters from the album name and capitalize the first character of each words in the album name. For example, I have an album named “Little angels (1)”. But in the album url, google wrote the name as “LittleAngels1″ (http://picasaweb.google.com/<my_user_name>/LittleAngels1). So I need to write a tiny function to take my actual album name and made it url ready as google. Here is the function:
<?php
function stripNonAlphaNumChars($dirtyStr)
{
$string = ucwords($dirtyStr); // capitalize the first characters of each word in the string
$patterns = ‘/[^a-zA-Z0-9]+/’; // reg. exp. for non alphanumeric characters
$replacements = ”; // replaced with empty string
$cleanStr = preg_replace($patterns, $replacements, $string); // return the clean string
return $cleanStr;
}
echo stripNonAlphaNumChars(‘The little angels (1)’);
// the output is: TheLittleAngels1
?>
Very large function huh ?!


