Php 从url&;中删除加号(&x2B;);在Yii中添加减号(-)

Php 从url&;中删除加号(&x2B;);在Yii中添加减号(-),php,yii,Php,Yii,我使用Yii框架创建了一个应用程序,我遇到了如下问题: http://example.com/articles-89/Perk+and+UPR+stress+measurement/ 我需要像这样改变: http://example.com/articles-89/perk-and-upr-stress-measurement/ 添加-此符号,并将大写字母添加到小写字母中 我正在使用Yii&我的配置文件是 main.php 'urlManager'=>array( 'u

我使用Yii框架创建了一个应用程序,我遇到了如下问题:

http://example.com/articles-89/Perk+and+UPR+stress+measurement/
我需要像这样改变:

http://example.com/articles-89/perk-and-upr-stress-measurement/
添加
-
此符号,并将大写字母添加到小写字母中

我正在使用Yii&我的配置文件是

main.php

'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            'articles-<id:\d+>/<title:.*?>' => array('articles/view', 'urlSuffix' => '/', 'caseSensitive' => false),
            '/<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),
'urlManager'=>数组(
“urlFormat'=>“路径”,
'规则'=>数组(
'articles-/'=>array('articles/view','urlSuffix'=>'/','caseSensitive'=>false),
“//”=>“/视图”,
'///'=>'/',
'//'=>'/',
),
),

如果我能帮助任何人,我真的很感激

您应该修改
标题的模式,如下所示(允许小写字符和
-
符号):

[a-z\-]+
而不是
*?

并准备用于将部分url转换为小写和-符号的函数,例如:

function convert($string)
{
    $replaceFrom = array('+');
    $replaceTo = array('-');

    $string = strtolower($string);

    return str_replace($replaceFrom, $replaceTo, $string);
}

使用此功能,您应该在生成URL的位置准备
title
参数,例如在创建超链接等中。

请如何使用该参数