ですが、正規表現書きます ><
Android のデバイス名が欲しい時があります。
ユーザーエージェントから抜き出すのですがその正規表現書いてみました。
Gist に上げたので修正なんかもお願いします。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/\(Linux; U; Android [0-9A-Za-z\.\;\-\_\s]+; ([0-9A-Za-z\-\_\/\s]+) Build\/[0-9A-Za-z\.\_\-]+?\)/i |
こんな風に
if (stripos($useragent, 'android')) { if (stripos($useragent, 'mobile')) { // android 標準ブラウザ, android Miren Browser $matches = array(); if (preg_match('/\(Linux; U; Android [0-9A-Za-z\.\;\-\_\s]+; ([0-9A-Za-z\-\_\/]+) Build\/[0-9A-Za-z\.\_\-]+?\)/i', $useragent, $matches)) { echo '' . $matches[1] . ' :: ' . str_replace($matches[1], '' . $matches[1] . '' , $useragent) . ' '; } } else { // android Firefox, android Opera mobile, android Opera mini echo 'not android mobile :: ' . $useragent . ' '; } } else { // PC firefox, PC chrome, PC Opera, PC IE, PC Safari(win), PC Safari(mac) echo 'not android :: ' . $useragent . ' '; }
ユーザーエージェント一覧は 色々やってみてはみる を参考にしました。
ちょっと最新の機種が入ってないけど・・・。