Home  >  Article  >  php教程  >  PHP generates friendly URL [for SEO]

PHP generates friendly URL [for SEO]

大家讲道理
大家讲道理Original
2016-11-08 14:08:081325browse

public function friendlyURL($string, $replacement = '-') {
        $map = array(
            '/à|á|å|â|ä/' => 'a',
            '/è|é|ê|ẽ|ë/' => 'e',
            '/ì|í|î/' => 'i',
            '/ò|ó|ô|ø/' => 'o',
            '/ù|ú|ů|û/' => 'u',
            '/ç|č/' => 'c',
            '/ñ|ň/' => 'n',
            '/ľ/' => 'l',
            '/ý/' => 'y',
            '/ť/' => 't',
            '/ž/' => 'z',
            '/š/' => 's',
            '/æ/' => 'ae',
            '/ö/' => 'oe',
            '/ü/' => 'ue',
            '/Ä/' => 'Ae',
            '/Ü/' => 'Ue',
            '/Ö/' => 'Oe',
            '/ß/' => 'ss',
            '/ /'=>' ',
            '/ /'=>'',
            '/~|·|!|@|#|¥|%|…|&|×|(|)|-|\+|=|『|【|』|】|、|:|;|“|”|’|《|,|》|。|?|\/|—|_|‘|:|√|<|°|丶/'=>' ',
            '/[^\w\s\x80-\xff]/' => ' ',
            '/\\s+/' => $replacement
        );
 
        $string = preg_replace(array_keys($map), array_values($map), $string);
        $string = preg_replace('/\\s+/',$replacement, strtolower($string));
        $string = trim($string,$replacement);
        return $string;
    }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn