$userAgent = $_SERVER['HTTP_USER_AGENT']; $devices = array( "iPhone" => "(iPhone)", "Android" => "(Android)", "Windows Phone" => "(Windows Phone)", "iPad" => "(iPad)" ); $deviceType = "PC"; foreach ($devices as $device => $regexp) { if (preg_match("/" . $regexp . "/i", $userAgent)) { $deviceType = $device; break; } } if ($deviceType === "PC") { // PC端代码 } else { // 移动端代码 }
标签:iPad,访问,Phone,PC,deviceType,userAgent,Android,PHP From: https://www.cnblogs.com/blts/p/17108436.html