check whether string is in array in php & mysql

php & mysql question. need to make list of allowed domains of sites. then i will have big lists of links. need to modify only that links, which are of allowed domain.
how to make this more correct? i can use in_array, and, so, write list of allowed domains in php code as array, or write in text file and read from it to array. but if many allowed domains, it can find whether the domain being checked is in array after long time, because it can be in last looked position in array. i know that there are methods of fastly searching element in array of sorted elements, like searching in dictionary. i hope you understand. for example look middle of array, and look, which letter is first letter there, then look middle of right side or middle of left side, and so on. i want to know, whether mysql uses this method or like that? i know that there are index columns in mysql. i hope it uses fast searching. so i can make one index column with domains in it…

i have made something like this or this already… now i show the code that i used, though there is opposite: checked, whether uri is not allowed (and not just domain, but uri in this case):
$j1=
mysql_query(
'SELECT adres FROM unneeded WHERE adres = \''.$oneadres.'\'',
$connection
)
;
if(mysql_num_rows($j1)>0){
$thisadresiscorrect=false;
}

where “unneeded” table properties are: it is MyISAM, there is one column, it is primary, unique, btree, varchar(300) .

i want to know, how to make this checking more correct, if possible. may be there are other ways?

now i will ask this giving link in php and mysql freenode irc channels. and may be, then in some forums.

2011-11-23 8:30 pm utc+4 : that column should be indexed. there are 2 ways of indexing: btree and hash table. hash table is better for this case, as i know.

Leave a Reply