Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function generateUri($title) {
- $title = strtolower($title);
- // Reemplazamos tildes y etc.
- $patterns = array (
- '/á/',
- '/é/',
- '/í/',
- '/ó/',
- '/ú/',
- '/à/',
- '/è/',
- '/ù/',
- '/ì/',
- '/ò/',
- '/ñ/',
- '/Á/',
- '/Í/',
- '/É/',
- '/Ó/',
- '/Ú/',
- '/À/',
- '/È/',
- '/Ù/',
- '/Ì/',
- '/Ò/'
- );
- $replaces = array (
- 'a',
- 'e',
- 'i',
- 'o',
- 'u',
- 'a',
- 'e',
- 'u',
- 'i',
- 'o',
- 'n',
- 'a',
- 'i',
- 'e',
- 'o',
- 'u',
- 'a',
- 'e',
- 'o',
- 'u',
- 'a',
- 'e',
- 'u',
- 'i',
- 'o'
- );
- $title = preg_replace($patterns, $replaces, $title);
- // Vamos a separar las words.
- $words = explode(' ', $title);
- $strlen = 0;
- // Recorremos y vemos que no pase el limite.
- $ret = '';
- foreach ($words as $w) {
- if ( ($strlen + strlen($w) ) > LIMIT ) {
- // Supera al limite, chequeamos que no
- // NOSSA, NOSSA
- // que no sea la unica palabra, asi no devolvemos una uri vacia.
- if (!$ret) {
- // Tonces efectivamente es la unica palabra, la cortamos.
- $ret = substr($w, 0, LIMIT);
- }
- // Salimos del for
- break;
- }else{
- $ret .= $w . '-';
- }
- }
- $valid = array (
- 'a',
- 'b',
- 'c',
- 'd',
- 'e',
- 'f',
- 'g',
- 'h',
- 'i',
- 'j',
- 'k',
- 'l',
- 'm',
- 'n',
- 'o',
- 'p',
- 'q',
- 'r',
- 's',
- 't',
- 'u',
- 'v',
- 'w',
- 'x',
- 'y',
- 'z',
- '-',
- '_'
- );
- $return = '';
- for ($i=0;$i<strlen($ret);$i++) {
- if ( in_array ($ret[$i], $valid) ) {
- $return .= $ret[$i];
- }
- }
- $return = preg_replace ('/(-)+/', '-', $return);
- $return = preg_replace ('/(-)+$/', '', $return);
- $return = preg_replace ('/^(-)/', '', $return);
- if(!$return) {
- $return = 'mas-frases-en-gusta-us';
- }
- return $return;
- }
Add Comment
Please, Sign In to add comment