Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Titlelize

DZone's Guide to

Titlelize

· ·
Free Resource

/**
* $title = "Hello world! This is a title";
* echo Helpers_Html::titlelizeEncode($title);
* echo "
"; * 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; } }
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}