I need some help trying to replace a letter from a string.
I have a mysql database with names of places, in spanish.
The thing is that the names(985 records) all have the spanish accents without the proper html-escape equivalent, and thus, the mobile browser can't recognize it and writes a ? sign, and it looks horrible.
So, Im trying to replace each accent with the proper html-escape equivalent (&-#-225; for á, &-#-237; for í, etc...)<-- without the '-'.
So when I post to the database it posts with those codes instead of the accent.
I'm making a routine to go over each letter of each name and look for these accents and replace them with the code.
This routine is supposed to work, but it doesnt work
Here it is, if you need more info please let me know.
i'm putting a '-' on the html-escape equivalents to prevent your browser from translating it to the proper character, so you can see the code.
************ begin ********
// $row has all the names
// some example names are "Café de la Plaza" "El Bodegón de Gaspar"
// I have to replace the accents for the proper code
// ex. é = "-&-#233; <-- without the '-'
while($row = mysql_fetch_row($dbResult))
{
echo "$row[0]<br>\n"; //<-- for comparison purposes only
$original = $row[0]; //<-- $original has the name
//$original = explode(" ",$row[0]); <-- tried but doesnt work
$num = strlen($original); //<-- $num has the lenght of the name
for($y=0;$y<$num;$y++) //<-- $num is the control
{
switch ($original[$y]) //<-- goes through all the letters to verify
{
case "á":
$original[$y] = "&-#-225;"; //<--repaces the letter with "&" only
// so for example "Café" becomes Caf&" , not what i want...
// also tried the code escapes "&\#225;" and "\á"
// also tried this other function:
//substr_replace($original,"é",$y,0); <-- doesnt do anything
break;
case "é":
$original[$y] = "&-#-233;";
break;
case "í":
$original[$y] = "&-#-237;";
break;
case "ó":
$original[$y] = "&-#-243;";
break;
case "ú":
$original[$y] = "&-#-250;";
break;
case "ñ":
$original[$y] = "&-#-241;";
break;
case "ü":
$original[$y] = "&-#-252;";
break;
case "Ñ":
$original[$y] = "&-#-209;";
break;
}
}
//$original = implode($original); // <-- tried in conjuction with explode() but doesnt work
echo "$original <br>$num\n<br>\n\n"; // <-- just to check output
// when i finally get the output right i will replace this for an
// modify sql statement to modify the database
}
************* end ***************
Any comments, solutions, ideas are very very welcome.
Thanks for the help





Reply With Quote




Bookmarks