1

I used this code from Stackoverflow to creat a title slug from a string

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;
 } 

It is working fine for most of the strings. but getting this for some strings like "Азур и Азмар / Azur et Asmar". what should i change now?

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

1 回答 1

2

Just try changing

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

to

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