Someone overheard a friend and I chatting about a website and it’s tag cloud script. I mentioned that it’s pretty easy to create and that I had already created a php function. He asked me to dig it up, so I present to you a cloud script in it’s simplest form.

Cloud

<?php
 
$ceiling = 50;
 
class cloud {
 
	function setTop($top) {
		global $ceiling;
		$ceiling = $top;
	}
 
	function sizeMe($name,$times) {
		global $ceiling;
		$times = ($times / $ceiling) * 100;
		if ($times <=20)
			$size = 1;
		else if ($times>=11 && $times <=40)
			$size = 2;
		else if ($times>=21 && $times <=60)
			$size = 3;
		else if ($times>=31 && $times <=80)
			$size = 4;
		else
			$size = 5;
		// You should really replace this with a return $size, this is just for demonstration purposes
		echo "<span class=\"a$size\"><a href=\"#\">$name</a></span> ";
	}
}
?>

It’s pretty straight forward and easily modified. You setTop based on the number of entries in your database, then pass $name and the number of times it appears to the sizeMe function. If you have any questions or suggestions please let me know. I tried to keep this simple.

In this example I created classes, a1, a2, a3, a4 and a5 that I defined font-size for in a css file.

Strip Characters From A Filename

<?php
 
function renameStripChars($directory, $pattern, $replacement, $verbose = false) {
  if($curdir = opendir($directory)) {
   while($file = readdir($curdir)) {
     if($file != '.' && $file != '..') {
 
       $dstfile = $directory . '/' . preg_replace($pattern, $replacement, $file); 
	   $srcfile = $directory . '/' . $file;	 
 
	   rename($srcfile, $dstfile);
 
       if(is_dir($srcfile) && $verbose) {
	      renameStripChars($srcfile, $pattern, $replacement, $verbose);
       }
     }
   }
   closedir($curdir);
  }
}
 
// An example of how I used it
renameStripChars('picsTest', '/[^\w\d\.-\s]+/', '', true);
renameStripChars('picsTest', '/[\s]+/', '_', true);
renameStripChars('picsTest', '/[-]+/', '-', true);
renameStripChars('picsTest', '/[_]+/', '_', true);
 
?>

I wrote this function because I had a boatload of images with ridiculous characters in them and I wanted them out before I uploaded them somewhere. Most frameworks have a similar function built in but if you’re looking for a quick fix, this is perfect for you.