1

Stackoverflow のこのコードを使用して、文字列からタイトル スラッグを作成しました

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 
4

1 に答える 1

2

変えてみてください

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

$text = iconv('utf-8', 'us-ascii//IGNORE', $text);
于 2016-03-06T15:20:09.553 に答える