J
J
Julia Kovalenko2016-06-16 13:37:29
Yii
Julia Kovalenko, 2016-06-16 13:37:29

How to find namesakes in php?

I have a surname of the user and a certain base of surnames.
You need to find family members.
That is, for 'Ivanov' the surname 'Ivanova' should also be found, but not 'Ipanov'.
What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
imhuman, 2016-06-16
@imhuman

In general, not such a trivial task to solve in one line. In fact, you need to bring each surname to the male version. To study the rules of formations and declensions of surnames, there is not much that will work out there. For example, replace -ova(-eva) at the end with -ov(-ev). -ko, -chuk leave unchanged and so on. Surnames that are at the same time dictionary nouns should also be left unchanged. Well, to make a dictionary of exceptions, you can’t do without it, most likely. And then make a strict comparison of male variants of surnames.

A
Andrey Boychenko, 2016-06-16
@Ka4_Piton

$lastname = last name
Only instead of an asterisk, put the fields from which you need data

T
ThunderCat, 2016-06-16
@ThunderCat

Here the question is rather for linguists than for programmers, decide on the algorithm for the formation of "name names" for ANY surname, after that it will be easier to compose a request than to send 2 bytes. In reality, it is enough to determine the endings by the surname, separate them and get the root of the surname and the maximum length of possible surname strings:

$DB->exec("SELECT *
FROM `table` 
WHERE `lastname` LIKE '?%'  
and CHAR_LENGTH(`lastname`) < ?", array($lastNameRoot,$lastNameMaxLenght));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question