2015-04-21 17:41



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:
        $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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanmu2013 duanmu2013 6年前

    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.

    点赞 评论 复制链接分享