Jump to content

[SOLVED] How to detect spanish characters (ñ, ú,ó,...) with php


mixpage65

Recommended Posts

Hey guys, i have a question. I have a dynamic Spanish homepage written in php and uses mysql. As all you know in Spanish there are special characters like ñ,ó, etc. ( alt 164, alt 162, etc).  If one vowel have this " ` " character above it means that the power of pronunciation is in that vowel. People tends to forget to write that.

 

The problem is that if the user stores something containing those special characters, and another user searches that specific data and forgets to write the special character ( ó,í,á,é,ú, ñ, Ñ ) then the search is not successful. It can happen vice-versa.

 

What approach i can use to solve that problem? - I was thinking on checking the value inputted before the search or store action and see if the user wrote any of those special characters to eliminate it. For example if the user stored "español", store it in the d-base as "espanol". The same when searching, if the user wrote "canción", convert it to "cancion" and then do the query.

 

What do you think? can regular expressions solve my problem?

 

Thanks in advance and sorry for the spelling, english is my second language.

 

 

You might have it so that your php query is manipulated before sending it to mysql.

 

User searches for: "pagina"

 

Php looks for any characters that are vowels(aeiou) and replaces them with %vowel%.

 

So the search for pagina becomes $search = 'p%a%g%i%n%a%';

So your $SQL = "SELECT *FROM yourtable WHERE columnname LIKE '$search';

 

I haven't tested this, but it's an idea.

 

 

Although, that many wildcards may return unwanted results.

i am thinking str_replace also, do it when the data is inserted into a db and right after the seach button is hit

ie

turn á into &#225 via str_replace, and then the search comes up correct because it will be looking for &#225 as a string rather than possibly finding, and then html will turn it back into á upon redisplay

 

this does not take into account case sensitivity though

@Lodius

That doesn't necessarily solve his search problem.  His problem is that he needs to find a match for potential accents.

 

So like for pàgina.  Some people might spell it: pagina, pàgina, página, pÀgina, pÁgina, all which should be considered "close enough" to find the actual word.

 

So, if anything, mixpage65 would have to manipulate the query string into several querys: a combination of (number of vowels) * (number of possible accents) and then combine however many searches that might be to look for a result.  I still say it's best to build a mysql Regexp, or stick with the wildcards.

xtopolis

 

duh, i completely missed that part, i thought the prob was how to recognise special characters in a search, i was wayyyyy off, and now i realize how easy my solution would be to accomplish, but yeah his problem is very different, ill shut up now :D

couldn't you use str_replace to fix all that buy converting

pagina, pàgina, página, pÀgina, pÁgina

to

pagina

like this

<?php
$replace = array("à","á","À","Á");
$string = str_replace($replace,"a",$string);
?>

 

Scott.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.