All pastes #438541 Raw Edit

Anonymous

public php v1 · immutable
·published 2007-04-13 18:09 UTC
rendered paste body
<?php// sluGen is a 'slug' generator.// 'slugs' are often used in blog urls instead of id numbers, etc.// A good example of a site that uses slugs is Digg./////////////////////////////////////////////////////////////////////// The first argument is the string that is to be 'slugged'.// The second argument is the character which replaces spaces (most sites use underscores ("_") and hyphens ("-")./////////////////////////////////////////////////////////////////////// Example: sluGen("10 Tips for Optimizing MySQL Queries (That don’t suck)", "-")// Becomes: 10-tips-for-optimizing-mysql-queries-that-dont-suckfunction sluGen($string, $spacer){	$slug = $string; $slug = strtolower($slug); $slug = str_replace(" ", $spacer, $slug);		for($i=0; $i<strlen($slug); $i++){		$alphanum = array("", $spacer, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");		if(!in_array($slug[$i], $alphanum)){$slug = str_replace($slug[$i], "", $slug);}	}		return $slug;	}echo sluGen("Fork PHP! (and speed up your scripts)", "-");//fork-php-and-speed-up-your-scripts?>