1

I want to create a folder with the following name:

1.Visit to L’Aventure Du Sucre Museum and Factory

2.Visit to Vallée des Couleurs

but I am getting :

  1. Visit to L’Aventure Du Sucre Museum and Factory
  2. Visit to Vallée des Couleurs

how to deal with these special characters ? I know it is a well-known issue but I can't make it works please help

here is my code :

$Title = "Visit to L’Aventure Du Sucre Museum and Factory";

mkdir('uploadImage/'. $Title, 0777, true);

1 Answers1

2

Try to slugify your directory names

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

  return $text;
}

$Title = "Visit to L’Aventure Du Sucre Museum and Factory";
$Title = slugify($Title)
mkdir('uploadImage/'. $Title, 0777, true);
Bart
  • 1,268
  • 2
  • 12
  • 14