I have a cache file with an array of user agents.
When i print each user agent out, this is what it looks like:
@^Mozilla/5\.0 \(.*Linux i686.*\) AppleWebKit/.* \(KHTML, like Gecko\).*Chrome/6\..*Safari/.*$@
@^Mozilla/5\.0 \(X11; U; Linux.*; .*; rv\:1\.9\..*\) Gecko/.* Firefox/.* Maemo Browser 1\.7\..*$@
@^Mozilla/5\.0 \(.*Linux i686.*\) AppleWebKit/.* \(KHTML, like Gecko\).*Chrome/7\..*Safari/.*$@
@^Mozilla/5\.0 \(.*Linux i686.*\) AppleWebKit/.* \(KHTML, like Gecko\).*Chrome/8\..*Safari/.*$@
@^Mozilla/5\.0 \(.*Linux i686.*\) AppleWebKit/.* \(KHTML, like Gecko\) .*Iron/6\..* Safari/.*$@
@^Mozilla/5\.0 \(.*Linux i686.*\) AppleWebKit/.* \(KHTML, like Gecko\) .*Iron/7\..* Safari/.*$@
@^Mozilla/5\.0 \(.*Linux i686.*\) AppleWebKit/.* \(KHTML, like Gecko\).*Chrome/9\..*Safari/.*$@
ect ect....
Now it looks like these user-agents have been escaped, so I’ve stripslashes() them.
I’ve also noticed some invalid characters here (@,^,.*$@), so I’ve str_replaced() them with nothing.
And the end result:
Mozilla/5.0 (.Linux i686.) AppleWebKit/. (KHTML, like Gecko).Chrome/6..Safari/
Mozilla/5.0 (X11; U; Linux.; .; rv:1.9..) Gecko/. Firefox/. Maemo Browser 1.7.
Mozilla/5.0 (.Linux i686.) AppleWebKit/. (KHTML, like Gecko).Chrome/7..Safari/
Mozilla/5.0 (.Linux i686.) AppleWebKit/. (KHTML, like Gecko).Chrome/8..Safari/
Mozilla/5.0 (.Linux i686.) AppleWebKit/. (KHTML, like Gecko) .Iron/6.. Safari/
Mozilla/5.0 (.Linux i686.) AppleWebKit/. (KHTML, like Gecko) .Iron/7.. Safari/
Mozilla/5.0 (.Linux i686.) AppleWebKit/. (KHTML, like Gecko).Chrome/9..Safari/
I’m planning to insert these user-agents into a database (already full of hundreds of thousands), and I’m worried they’re still invalid in some way that I haven’t noticed.
If I do insert these into the DB and they’re invalid, I would then have to delete the whole DB, and start all over…
So I don’t want to take any risks…
Can you guys spot anything wrong with these user-agent strings?
🙂
These are regular expressions, not invalid characters. If you simply match the strings against the user agent string, they will not match. They are meant to be matched as regular expressions.