Tuesday, 15 March 2011

String comparison with multiple words in PHP -


I'm still working on my library database.

How can I compare strings, with PHP, many words in a different order, such as Gaius Julius Caesar and Caesar Gayus Julius For what do they match? Comma, dash, double spaces etc. will be removed before comparing.

To put strings in two arrays and to check with in_array () If each element of the first one is included in another, a proper solution for a couple of wires Maybe, but it seems a waste of the CPU to check the list of more than 5,000 names from Maria DB table (compared to the 5,000 × 5,000 = 25,000,000 comparison).

Suggestion

Like it:

 < Code> $ A = "Gius Julius Caesar"; $ B = "Caesar Geese Julius Putin"; $ AR1 = explosion ('', $ a); $ AR2 = explosion ('', $ B); $ AR3 = array_intersect ($ AR1, $ AR2); Print_r ($ ar3);  

yield

  array ([0] => Gaius [1] => Julius [2] => Caesar) < / Code> 

To see if they match - just compare your count ()


No comments:

Post a Comment