Re: question regarding content search in array with PHP
Omer Zak <w1-W6cp89mEpD1mR6Xm/[email protected]> Tue, 18 Dec 2007 19:45:43 +0200
| Newsgroups | gmane.culture.hackers.israel |
|---|---|
| Message-ID | <[email protected]> |
Since you want to use PHP, I assume that you want to do this when
processing Web requests.
Therefore, I would store the array as a DB (such as MySQL) table.
The table will have two columns:
- Word (indexed, non-unique key)
- FullString
For 'linux', you'll have
'linux','linux'
For 'mac os', you'll have
'mac','mac os'
'os','mac os'
Then, when you get the string from the user, split it into words and
query for full strings corresponding to each word (using, for example:
SELECT FullString FROM StringsTable WHERE Word='os';
Of course, you should use the appropriate prepared queries to guard
against SQL injection vulnerabilities).
Now you'll have small number of full strings to be considered, and can
apply your complicated and inefficient heuristic algorithm to determine
which full string corresponds best to the user's string.
--- Omer
On Tue, 2007-12-18 at 19:06 +0200, ik wrote:
> Hello list,
>
> I have an array that for the example will look as follows:
>
> linux, windows, mac os, beos, os/2, freebsd, netbsd, irix ....
>
> And a string:
>
> "linux kernel 2.6.24"
>
> Now I wish to find the closest value of the string in the array -> "linux".
> But the problem as you can see, is that the string contain more
> content then the array value.
> I can think on many unefficient ways to find the part of string as an
> array value, but I'm looking for an efficient way to do it. specially
> if I need to serve a lot of strings on after the other...
> The problem is, that I must use PHP (because I can think on an answer
> using Perl, that I haven't tested).
>
> Any ideas how I can do it in an efficient way ?
--
MS-Windows is the Pal-Kal of the PC world.
My own blog is at http://www.zak.co.il/tddpirate/
My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html