I have php document signup.php which save the content from form (in form.php document) to MySQL base. The problem arises when I want to reformat the input content. I want do decode UTF-8 charachters like à->a.
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$course=$_POST['course'];
$chain="prêt-à-porter";
$pattern = array("'é'", "'è'", "'?'", "'ê'", "'é'", "'è'", "'?'", "'ê'", "'á'", "'à'", "'?'", "'a'", "'?'", "'á'", "'à'", "'?'", "'?'", "'?'", "'ó'", "'ò'", "'?'", "'?'", "'ó'", "'ò'", "'?'", "'?'", "'í'", "'ì'", "'?'", "'?'", "'í'", "'ì'", "'?'", "'?'", "'ú'", "'ù'", "'ü'", "'?'", "'ú'", "'ù'", "'ü'", "'?'", "'y'", "'?'", "'Y'", "'?'", "'?'", "'?'", "'?'", "'?'", "'?'", "'?'");
$replace = array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E', 'a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A', 'A', 'o', 'o', 'o', 'o', 'O', 'O', 'O', 'O', 'i', 'i', 'i', 'I', 'I', 'I', 'I', 'I', 'u', 'u', 'u', 'u', 'U', 'U', 'U', 'U', 'y', 'y', 'Y', 'o', 'O', 'a', 'A', 'A', 'c', 'C');
$chain = preg_replace($pattern, $replace, $chain);
echo $chain; // print pret-a-porter
$first_name = preg_replace($pattern, $replace, $first_name);
echo $first_name; // does not change the input!?!
Why it works perfectly for $chain, but for $first_name or $last_name doesnt work?
Also i try
echo $first_name; // print áááááábééééééb????
$trans = array("á" => "a", "é" => "e", "?" => "s");
echo strtr("áááááábééééééb????", $trans); // print aaaaaabeeeeeebssss
echo strtr($first_name,$trans); // print áááááábééééééb????
but the problem, as you can see, is same!
See Question&Answers more detail:
os