I am saving the content and title from a WYSIWYG widget (screenshot below) in an SQL database. I am also creating a new file every time (php). My problem is that the new file has a weird name because of the unicode. I am trying to make it work with the unicoded version of the name.
This is my WYSIWYG form :
This is the part that saves the content and title in the database without any unicode issues because the UTF8 was set for the database fields :
$sql = "INSERT INTO `articles`(`Content`, `Article_Name`) VALUE ('$_POST[htmlcontent]','$_POST[articlename]')";
And this is the part that creates the file but the name has an issue with the unicode :
$myfile = fopen("$articlename.php", "w") or die("Unable to open file!");
I first tried this:
$unicoded = iconv('windows-1250', 'utf-8', file_get_contents($articlename));
$myfile = fopen("$unicoded.php", "w") or die("Unable to open file!");
and then this:
function utf8_fopen_read($articlename) {
$fc = iconv('windows-1250', 'utf-8', $articlename);
$handle=fopen("$fc", "w");
fwrite($handle, $fc);
fseek($handle, 0);
return $handle;
}
$myfile = utf8_fopen_read("$articlename.php");
They all return a file named "φφφĎâ€.php" although it is supposed to be named "φφφ.php"
UPD:
I tried this and the console returns an empty string :
$fc = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $articlename);
echo "<script>console.log('$fc')</script>";
I also tried this :
$name = urlencode($_POST["articlename"]) . ".php";
echo "<script>console.log('$name')</script>";
$myfile = fopen($name, "w") or die("Unable to open file!");
but the name is now something like this '%CF%86.php'