【问题标题】:Error while Creating title Slug Notice: iconv(): Detected an illegal character in input string in创建标题 Slug 时出错 注意:iconv():在输入字符串中检测到非法字符
【发布时间】:2016-06-19 23:09:23
【问题描述】:

我使用 Stackoverflow 中的这段代码从字符串中创建标题 slug

function slugify($text)
{
 // replace non letter or digits by -
 $text = preg_replace('~[^\pL\d]+~u', '-', $text);

 // transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);

// trim
 $text = trim($text, '-');

// remove duplicate -
$text = preg_replace('~-+~', '-', $text);

// lowercase
$text = strtolower($text);

if (empty($text))
{
  return 'n-a';
}

 return $text;
 } 

它适用于大多数字符串。但是对于像“Азур и Азмар / Azur et Asmar”这样的字符串会得到这个。我现在应该改变什么?

Notice: iconv(): Detected an illegal character in input string in 

【问题讨论】:

    标签: php slug slugify


    【解决方案1】:

    尝试改变

    $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
    

    $text = iconv('utf-8', 'us-ascii//IGNORE', $text);
    

    【讨论】:

      猜你喜欢
      • 2012-08-08
      • 2014-08-16
      • 2012-02-02
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 2021-05-09
      • 2020-08-29
      相关资源
      最近更新 更多