Home > php教程 > PHP源码 > PHP生成友好URL

PHP生成友好URL

PHP中文网
Release: 2016-05-25 17:13:55
Original
1264 people have browsed it

功能: 生成友好URL,利于URL SEO
支持中文,韩文,日文,英文。
有什么不足的地方还希望大家完善。

[PHP]代码    

    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 = trim($string);
        $string = preg_replace(array_keys($map), array_values($map), $string);
       	$string = preg_replace('/\\s+/',$replacement, strtolower($string));
       	$string = trim($string,$replacement);
        return $string;
    }
Copy after login

                   

                   

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Articles by Author
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template