mixpage65 Posted July 16, 2008 Share Posted July 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 16, 2008 Share Posted July 16, 2008 the only way i could see how to do this is yo put every string throught a bunch of str_replace() commands one for each vowel. Scott. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted July 16, 2008 Share Posted July 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted July 16, 2008 Share Posted July 16, 2008 dbl post, I was also going to say, you could use a mysql regular expression if need be. Create the function in php and send to mysql. Quote Link to comment Share on other sites More sharing options...
mixpage65 Posted July 16, 2008 Author Share Posted July 16, 2008 thank guys for the fast reply. I will try all that stuff tonight. I will keep you informed. Thanks again. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted July 17, 2008 Share Posted July 17, 2008 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 á via str_replace, and then the search comes up correct because it will be looking for á 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 Quote Link to comment Share on other sites More sharing options...
xtopolis Posted July 17, 2008 Share Posted July 17, 2008 @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. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted July 17, 2008 Share Posted July 17, 2008 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 Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 17, 2008 Share Posted July 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted July 17, 2008 Share Posted July 17, 2008 You can strip diacritical marks. Quote Link to comment Share on other sites More sharing options...
mixpage65 Posted July 19, 2008 Author Share Posted July 19, 2008 did it with a str_replace to all vowels and other special spanish characters when storing and reading, not the best way but the easiest and quickest , thanks. ex. $theString = str_replace('Á','A',$theString); Quote Link to comment Share on other sites More sharing options...
effigy Posted July 21, 2008 Share Posted July 21, 2008 There's another reference here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.