my mysql table contains an entry
Foo Bar
(i.e will potentially include capitals and whitespace)
I need search the DB using the string ‘foobar’ and match this
foobar is generated originally from the DB using:
$i = str_replace(' ','',$i);
$i = preg_replace("/[^A-Za-z0-9]/", "", $i);
$i = strtolower($i);
If only spaces are the problem, and your collation is case-insensitive:
if your collation is case-sensitive:
It will however result in a full-table scan, so not a great performance. Normalizing
fieldnameto what you are searching for, or another column with a normalizedfieldnamewould perform better, especially with an index on it.