【问题标题】:CodeIgniter URL_TITLE model?CodeIgniter URL_TITLE 模型?
【发布时间】:2013-06-11 09:08:01
【问题描述】:

这是 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

【问题讨论】:

    标签: codeigniter url-rewriting


    【解决方案1】:

    你可以用简单的方法做到这一点

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

    【讨论】:

      【解决方案2】:

      我会通过在application/helpers 中创建一个MY_url_helper.php 文件来“扩展” 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”与破折号- 还是下划线_ 进行转换

      【讨论】:

        猜你喜欢
        • 2013-06-09
        • 2011-01-31
        • 2014-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多