在 php 中转换特殊字符



我想创建一个具有以下名称的文件夹:

1.参观苏克雷冒险博物馆和工厂

2.参观山谷

但我得到:

  1. 参观苏™克雷冒险博物馆和工厂
  2. 参观库勒尔山谷©

如何处理这些特殊字符?我知道这是一个众所周知的问题,但我无法让它工作,请帮助

这是我的代码:

$Title = "Visit to L’Aventure Du Sucre Museum and Factory";
mkdir('uploadImage/'. $Title, 0777, true);

尝试修改目录名称

function slugify($text){
  // replace non letter or digits by -
  $text = preg_replace('~[^pLd]+~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);
  return $text;
}
$Title = "Visit to L’Aventure Du Sucre Museum and Factory";
$Title = slugify($Title)
mkdir('uploadImage/'. $Title, 0777, true);

最新更新