Hello people,
I have a form where I post a Spanish Word with a Spanish accent on the word. Let's say, the word is Agrícóla.
I submit the form and then I build a mysql query with the content of the text box. Something like this:
select * from farm where FARM_ESTITLE like '%Agrícóla%'
If I print the query in my code, I actually have this:
select * from farm where FARM_ESTITLE like '%Agrícóla%'
This query does not return anything. So I copied this query and tested it insqlyog and it returned rows. But now what is happening is really strange, I copied the query from sqlyog and paste it in my code and refresh the page so it uses this static query instead. Well it actually returned the rows.
Also, the printed query on my page was this:
select * from farm where FARM_ESTITLE like '%Agr�c�la%'
So what I am assuming here is that the accent submitted by the browser is somewhere not recognized when sent to the server. So what I did then is creating a function to change the letter with the accent to the non-accent equivalent and did some testing to see what is happening.
This is what I am doing.
$replace = array(
'a' => array('à','â','ä'),
'e' => array('è','ê','ë','é'),
'i' => array('ì','î','ï','í'),
'o' => array('ò','ô','ö','ó'),
'u' => array('ù','û','ü')
);
// loop through all replacements and apply them
foreach ($replace as $by=>$what) {
$str = str_replace($what,$by,htmlspecialchars($_POST["search"]));
}
// done!
echo $str;
<form name="frm" action="testesp.php" method="post">
<input type="text" value="Agrícóla" name="search">
<input type="submit" value="ok">
</form>
You can see test the script here:
http://gatewaytosouthamerica.com/mckaulick/testesp.php Even this does not work. Somewhere, the accent is being ignore by the server. Someone has any thought?
Thanks,
mckaulick