-1

I have a problem right now. When someone is ordering something which contains the character "æ", it make it into "à¦", which destroys the mysql query, and ends the sentence there. For an example i got this:

#55*2*195*1 - 1,%%%%38. Burger dobbelt %%%%Kommentar%%%%Burgeren skal và¦re med friske agurker i stedet for syltede%%%%og uden ost. Pॠforhà¥nd tak %%%%%%%%100. Lasagne %%%%Dressing%%%%Ingen dressing,*;;124.20;;Niklas Smietana;;;;7;;*#

But when it insert it into the database, it ends up being like this:

#55*2*195*1 - 1,%%%%38. Burger dobbelt %%%%Kommentar%%%%Burgeren skal v

It just ends there. So what i want to do is that i want to replace every special characters like "æ", "ø", "å", "ü", "ö" and so on, in the "string", so it becomes "ae", "oe", "aa", "u", "o". I have tried with str_replace but it wont do it.

My code:

$product_name = $row['product_names'];
$product_name = str_replace("ø", "oe", $product_name);
$product_name = str_replace("É", "É", $product_name);
$product_name = str_replace("Ã", "à", $product_name);
$product_name = str_replace("¿", 'oe', $product_name);
$product_name = str_replace("¾", 'ae', $product_name);
$product_name = str_replace("æ", 'ae', $product_name);
$product_name = str_replace("Œ", 'aa', $product_name);
$product_name = str_replace("å", 'ae', $product_name);
$product_name = str_replace("š", 'oe', $product_name);
$product_name = str_replace("Ÿ", 'u', $product_name);

Do anybody in here have a solution on that?

Thanks in advance.

Charles
  • 50,943
  • 13
  • 104
  • 142
Ismail
  • 253
  • 1
  • 4
  • 19

1 Answers1

0

You should use mysql_real_escape_string() or mysqli_real_escape_string() to prevent mysql injections and to escape special characters.

Jeff Noel
  • 7,500
  • 4
  • 40
  • 66
  • Could you please give an example, because when i try to: $product_name = utf8_encode($product_name); it just edits the line into: #55*2*195*1 - 1,%%%%38. Burger dobbelt %%%%Kommentar%%%%Burgeren skal và ¦re med friske agurker i stedet for syltede%%%%og uden ost. Pà ¥ forhà ¥nd tak %%%%%%%%100. Lasagne %%%%Dressing%%%%Ingen dressing,*;;124.20;;Niklas Smietana;;;;7;;*# – Ismail Dec 06 '12 at 18:42
  • @IsmailIsmaiil I edited my post and deleted the utf8_encode answer I had written. – Jeff Noel Dec 06 '12 at 19:17