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.

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

报告相同问题?

悬赏问题

  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动