CodeIgniter URL_TITLE模型?

时间:2013-06-11 09:08:02

标签: codeigniter url-rewriting

以下是URl_title CI的示例,我知道此代码是执行此操作

$title = "Whats wrong with CSS";

$url_title = url_title($title, '_', TRUE);

// Produces: whats_wrong_with_css

但热转换,Ci中有一个函数来反转这样的东西并返回真值吗? 像这样?

// Produces: Whats wrong with CSS

2 个答案:

答案 0 :(得分:1)

嗨,你可以用简单的方式做到这一点

$title = ucfirst(str_replace("_",' ',$url_tilte));
echo $title;

答案 1 :(得分:0)

我会通过在MY_url_helper.php中创建application/helpers文件来“扩展”CI的URL帮助程序,并创建一个类似于umefarooq建议的函数。

/*
 * Un-create URL Title
 * Takes a url "titled" string as de-constructs it to a human readable string.
 */
if (!function_exists('de_url_title')) {

    function de_url_title($string, $separator = '_') {

        $output = ucfirst(str_replace($separator, ' ', $string));

        return trim($output);
    }

}

如果你已经加载了url帮助器,那么你就可以在整个应用程序中调用这个函数。

echo de_url_title('whats_wrong_with_css'); // Produces: Whats wrong with css

该函数的第二个($separator)参数允许您转换字符串,具体取决于字符串是url_title'd“是否为短划线-还是下划线_