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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.