Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "slug"

String Slug

<?php
 
function slugString($string, $replacement = '_')
{
  $aux = preg_quote($replacement, '/');
 
  $map = array(
    '/à|á|ã|â/' => 'a',
    '/è|é|ê|ẽ|ë/' => 'e',
    '/ì|í|î/' => 'i',
    '/ò|ó|ô|õ|ø/' => 'o',
    '/ù|ú|ũ|û/' => 'u',
    '/ç/' => 'c',
    '/ñ/' => 'n',
    '/ä|æ/' => 'ae',
    '/ö/' => 'oe',
    '/ü/' => 'ue',
    '/Ä/' => 'Ae',
    '/Ü/' => 'Ue',
    '/Ö/' => 'Oe',
    '/ß/' => 'ss',
    '/[^\w\s]/' => ' ',
    '/\\s+/' => $replacement
  );
 
  return preg_replace(array_keys($map), array_values($map), $string);
}
 

based on http://api.cakephp.org/view_source/inflector/#line-480

by Raphael Araújo on 2009-10-16, tagged helper  slug  text