Karl Timmermann wrote:

Hi,
Does anyone how I could accomplish this:

Basically, I have a MySQL database of names - some names have Spanish
accents in them. I want to build a web interface in PHP to search this
database. However, I want the names with Spanish accents to be shown
in the search results, regardless if the search was spelled without
the accents.

For example:

The database has "Niño" in it. I want it to be returned if the user
searched by using "nino" or "niño".

Any ideas? Maybe somehow using regular expressions in PHP or in MySQL
using Unicode somehow?

It has to be fast and on the fly. Thanks!

Could you store a second version of the name with accented characters converted and search on that? I found this function on the manual page for strtr() that you can use or adapt to your needs:


function removeaccents($string){
 return strtr(
  strtr($string,
   'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ',
   'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'),
  array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss',
   'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
}

--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to