The usual approach for matching fuzzy strings is things like calculating the levenshtein distance or implementing it as an n-gram search index. But for mapping user agents, this is overkill.
Rather, reduce the line you are looking for certain important criteria, then do something like
SELECT * FROM agents WHERE agent LIKE "Mozilla/5.0 (Linux; U; Android%) AppleWebKit/5% Version/4.0 Mobile Safari/5%"
So, you take off certain details in too much detail and replace them with% in your LIKE statement. However, you should rethink the architecture - I would keep only the important parts and not take into account the exact build number, etc. Also think about using an external library that already contains user agents and is suitable for you, no need to reinvent the wheel.
EDIT: as Volkerk pointed out above, the "external library" must be a PHP getbrowser . Just added for completeness; -)
source share