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 Pwm双极模式H桥驱动控制电机
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题