Generate unique identifier for a friendly url

class Helper_Mid extends Zend_Controller_Action_Helper_Abstract {
	function get($seed, $table = null) {
		$temp = preg_replace('/[\W|_]{1,}/','-', $seed);
		$temp = preg_replace('/[^a-zA-Z0-9-]/', '', $temp);
		$temp = preg_replace('/-$/','',$temp);
		$temp = preg_replace('/^-/','',$temp);
		$temp = strtolower($temp);
		if ($table != null) {
			$q = Doctrine_Query::create()
				    ->from($table)
				    ->where('mid LIKE ?', array("%$temp%"))
		    		->execute();
		    $rows = count($q);
		    if ($rows > 0) {
				$rows = $rows + 1;
				$temp = $temp . '-' . $rows;
		    }
		}
		return $temp;
	}
}

 

By Efra, published on October 30, 2010
http://www.phpzend.net

 Gabriel

Great!
Comment
*User:
Email:
Url:
*Comment:
  * Required fields
 
 
RSS RSS RSS