Re: Searching on AlphaNumeric Content Only

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

It's definitely possible to do when you do it in PHP, but not sure about on
the database side. You could read all records into memory and then iterate
over it with something like:

$toSearch = "4D24487PS"
$charsToIgnore = array('-','+',...);

foreach ($items as $k=>$item) {
  $itemVal = str_replace($charsToIgnore, '', $item);
  if (strcmp(str_replace($charsToIgnore, '', $toSearch), $itemVal) == 0) {
    $return = $item;
    break;
  }
}

This however might use a lot of memory, but if your DB is a manageable size
it should be ok. You can probably optimise it by iterating over a db result
set instead of reading everything into an array.

Cheers,
Tim
++Tim Hinnerk Heuer++

http://www.ihostnz.com

2009/9/3 <sono-io@xxxxxxxxxxxxx>

>        Is there is a way to search only for the alphanumeric content of
> field in a db?  I have an itemID field that contains item #'s that include
> dashes, forward slashes, etc, and I want people to be able to search for an
> item # even if they don't enter the punctuation exactly.
>
>        Here's an example:  let's say there is an itemID of 4D-2448-7PS but
> someone omits the dashes and searches on 4D24487PS.  Is it possible in PHP
> to have the find be successful, even if the search criteria doesn't exactly
> match what's stored in the field?
>
>        If this is possible, I'd appreciate it if someone could just point
> me in the right direction so I can read up on it.
>
> Thanks,
> Frank
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux