Trouble working with string functions with latin characters
Posted: Thu Feb 10, 2011 12:04 pm
I'm working with latin characters (Spanish) and I want to compare strings using strtok and strcmp to find some key words, the problem is when I want to search words like "Baño" , "Lavandería" into the string that I input in the form, the thing is that if I use strcmp in the action form (in this case import.php) like :
Previously I inserted in the form in <textarea> "Baño"
So:
The expected result is that "The word was found" but I'm not sure why it doesn't happens
In the other hand
if I try like this
Of course The word was found
I'd like to solve this , I've tried different aproaches
Like:
I did this because I thought that I could be easier just compare Banos=Banos,
but when I execute the code
// $_POST['txtDescription']=Baño
the result of echo is
Baño , but I expected Bano.
So I think that the 'problem' comes from $_POST['txtDescription'] because if I insert the string directly in strcmp, or str_replace it works, but when comes from $_POST['txtDescription'] doesn't.
this is the way that I insert the string
Thanks in advance for the support
Previously I inserted in the form in <textarea> "Baño"
So:
Code: Select all
if(strcmp("Baño",$_POST['txtDescription'])==0)
{echo "The word was found"}
else
{echo "The word wasn't found"}In the other hand
if I try like this
Code: Select all
if(strcmp("Baño","Baño")==0)
{echo "The word was found"}
else
{echo "The word wasn't found"}I'd like to solve this , I've tried different aproaches
Like:
Code: Select all
$txt=$_POST['txtDescription'];
$find=array("á","é","í","ó","ú","ñ");
$replace=array("a","e","i","o","u","n");
$txt2=str_replace($find,$replace,$txt);
echo $txt2."<br>";
but when I execute the code
// $_POST['txtDescription']=Baño
the result of echo is
Baño , but I expected Bano.
So I think that the 'problem' comes from $_POST['txtDescription'] because if I insert the string directly in strcmp, or str_replace it works, but when comes from $_POST['txtDescription'] doesn't.
this is the way that I insert the string
Code: Select all
<form action="import.php" method="post" enctype="text/plain">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="anchoLabel" valign="top">Texto:</td>
<td colspan="3"><label>
<textarea name="txtDescripcion" id="txtDescription" cols="45" rows="5" class="texto1"></textarea>
</label></td>
</tr>
</table>
<td width="40%" valign="middle">
<label><input type="image"
name="btnEnviar" id="btnEnviar" value="Subir"
src="images/btn_subir.png" /><!--<a onclick="mandarFormulario();" style="cursor:pointer;"><img src="images/btn_subir.png" border="0" align="absmiddle" /></a>-->
</label>
</td>
</form>
Thanks in advance for the support