1

Yeah, I have an issue with ÆØÅ randomly being replaced with æØå when loading/refreshing a php page calling on some values...

It worked fine until I added

$Filename = preg_replace("/[^a-zA-Z0-9]/", "", $Filename);

but that caused the script to delete the . in the file extensions, so I removed the code. Now it randomly replaces the letters upon load/refresh

$Filename=$_FILES['Filename']['name'];
$Description=$_POST['Description'];
$Contact=$_POST['Contact'];
$Time = gmdate('Y-m-d H:i');
$Title=$_POST['Title'];
$Filename = preg_replace("/[^a-zA-Z0-9]/", "", $Filename);

if(move_uploaded_file($_FILES['Filename']['tmp_name'], $target)) {
echo "Filen ". basename( $_FILES['Filename']['name']). " er nå lagt til blant Alta Botanikkforeningens funn.";
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("altabotanikk") or die(mysql_error()) ;

mysql_query("INSERT INTO picture (Filename,Description,Contact,Time,Title)
VALUES ('$Filename', '$Description', '$Contact', now(), '$Title')") ;
} else {
echo "Det skjedde noe galt her :/";
}

Due to it being random and no errors anywhere, I have no idea what is causing this.

HTML declaring UTF-8

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The Last Melody
  • 165
  • 1
  • 3
  • 10

1 Answers1

1

Have you made sure your MySQL connection is always UTF8?

mysql_connect("localhost", "root", "") or die(mysql_error()) ;
// make sure we're in UTF8 mode!
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
// continue
mysql_select_db("altabotanikk") or die(mysql_error()) ;

Then take it from there?

Even if your HTML has a meta tag for charset utf8, you'll need some more work. Incidentally, the new format for html5 (rather than the now-outdated html4.01) is:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    ...
  </head>
  <body>...</body>
</html>

The mysql connection also needs to be told that everything is in UTF8. And then for good measure, you also want to make sure your script itself (the .php file) is saved as a unicode file, because yes, that too can mess things up (fun times!)

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • Thank you, this caused the "random" issue to disappear, now it only displays the wierd characters, so now I just have to correct the characters in the DB, Thanks ^_^ – The Last Melody Jun 18 '13 at 23:10