DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Titlelize

07.01.2010
| 3100 views |
  • submit to reddit
        
/**
* $title = "Hello world! This is a title";
* echo Helpers_Html::titlelizeEncode($title);
* echo "<br/>";
* echo Helpers_Html::titlelizeDecode(Helpers_Html::titlelizeEncode($title));
*/
class Titlelize{

	 /**
	 * Gera titulos que podem ser recuperados
	 * @param string $string
	 */
	//return titlelizeEncode('ola mundo'):'ola-mundo'
	static function titlelizeEncode($string){
	   $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
	   return $slug;
	}
	
	
	//para usar em SQL algo como: '... title LIKE ?', titlelizeDencode('ola-mundo')
	//return 'ola?mundo'
	static function titlelizeDecode($string){
	   $slug=preg_replace('/-/', '?', $string);
	   return $slug;
	}

}