Return to Snippet

Revision: 10294
at December 16, 2008 16:02 by Zver


Initial Code
public function getStrippedTitle()
{
  $result = strtolower($this->getTitle());
 
  // strip all non word chars
  $result = preg_replace('/\W/', ' ', $result);
 
  // replace all white space sections with a dash
  $result = preg_replace('/\ +/', '-', $result);
 
  // trim dashes
  $result = preg_replace('/\-$/', '', $result);
  $result = preg_replace('/^\-/', '', $result);
 
  return $result;
}

Initial URL


Initial Description
This helps you stip anything from title. This example is from Symfony homepage.

Initial Title
getStrippedTitle

Initial Tags
regex

Initial Language
PHP