9k views
Function to slugify strings in PHP
This is a function to slugify (replace non-ASCII characters with ASCII characters) strings in PHP. It tries to replace some characters like ñ or ç to a similar ASCII character (for example, it will transform a ñ to a n).
PHP
- /**
- * Modifies a string to remove all non ASCII characters and spaces.
- */
- static public function slugify($text)
- {
- // replace non letter or digits by -
- // trim
- // transliterate
- {
- }
- // lowercase
- // remove unwanted characters
- {
- return 'n-a';
- }
- return $text;
- }
Hey, I know that many of you are symfony users. If you are, and you use Doctrine, you don't need to use this function; you can just call the urlize function provided by the class Doctrine_Inflector.
Submitted by miguelSantirso over 2 years ago — last modified less than a minute ago