Posted By

Zver on 12/16/08


Tagged

regex title symfony stip


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nkrstevski


getStrippedTitle


 / Published in: PHP
 

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

  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  

You need to login to post a comment.