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
Titlelize
/**
* $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;
}
}





