简体   繁体   中英

Error while Creating title Slug Notice: iconv(): Detected an illegal character in input string in

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 

Just try changing

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM