Re: return language of a word

From: Date: Mon, 29 Sep 2008 15:39:45 +0000
Subject: Re: return language of a word
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-281103@lists.php.net to get a copy of this message
2008/9/29 shahrzad khorrami <shahrzad.khorrami@gmail.com>: > hi all, > > is there any function to return us the lanuage of a word in the sentence? > > for example : My name is شهرزاد . > > when it sees شهرزاد notice that is a persian language. As others have said, you can check what unicode block the characters are from. For segments of text that are a little longer (one or two sentences), you can use n-gram based language identification, which can sometimes be spookily accurate. If you want to give that a go, there's a Pear package called Text::LanguageDetect which will do that [http://pear.php.net/package/Text_LanguageDetect]. It doesn't have trigrams for Persian in the lang.dat, but I don't imagine it would be too hard to add them, if that's what you need. -robin

« previous php.general (#281103) next »