Posted By


Zver on 12/16/08

Tagged


Statistics


Viewed 44 times
Favorited by 0 user(s)

getStrippedTitle


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. public function getStrippedTitle()
  2. {
  3. $result = strtolower($this->getTitle());
  4.  
  5. // strip all non word chars
  6. $result = preg_replace('/\W/', ' ', $result);
  7.  
  8. // replace all white space sections with a dash
  9. $result = preg_replace('/\ +/', '-', $result);
  10.  
  11. // trim dashes
  12. $result = preg_replace('/\-$/', '', $result);
  13. $result = preg_replace('/^\-/', '', $result);
  14.  
  15. return $result;
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.