douxing9567 2015-04-21 17:41
浏览 61
已采纳

清理URL生成器Symfony2在dev中工作但不在prod中工作

I'm using this code as a clean URL generator in Symfony 2.6:

namespace AppBundle\Utility;

class Utility {

    public static function getSlug($string, $separator = '-')
    {
        // Source: http://cubiq.org/the-perfect-php-clean-url-generator
        $slug = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
        $slug = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $slug);
        $slug = strtolower(trim($slug, $separator));
        $slug = preg_replace("/[\/_|+ -]+/", $separator, $slug);

        return $slug;
    }
}

It works fine in my dev environment, with special characters, but not in my prod environment (my server). It doesn't change characters like á é ñ %, they just disappear. Example "Artículo año 2000", it shows: "artculo-ao-2000".

I have installed PHP 5.5.23 in CentOS 5.11, I added UTF-8 as the default charset in http.conf for Apache and in php.ini, if I type "php app/check.php" everything is fine but it only suggests a PHP accelerator.

I tried uploading a file with a special character /holá.html, and it works fine.

I don't know what else to do. Is it because of the prod environment configuration?

  • 写回答

1条回答 默认 最新

  • duanmu2013 2015-04-21 18:40
    关注

    iconv() requires correct setlocale();. Make sure you are not changing it between environments and, if your dev dev machine is different than prod, chack if you have the correct locales installed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog