{"id":525,"date":"2011-05-12T10:58:53","date_gmt":"2011-05-12T01:58:53","guid":{"rendered":"http:\/\/stocker.jp\/diary\/?p=525"},"modified":"2011-05-12T11:16:09","modified_gmt":"2011-05-12T02:16:09","slug":"browser_class","status":"publish","type":"post","link":"https:\/\/stocker.jp\/diary\/browser_class\/","title":{"rendered":"\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3092\u697d\u306b\u3059\u308b\u305f\u3081\u306ePHP\u95a2\u6570\u3068\u3001Mac\u304b\u5224\u5225\u3059\u308b\u95a2\u6570"},"content":{"rendered":"<p>\u3053\u306e\u30d6\u30ed\u30b0\u3092\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3059\u308b\u306b\u3042\u305f\u3063\u3066\u3001\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3092\u697d\u306b\u3059\u308b\u305f\u3081\u306b\u30d6\u30e9\u30a6\u30b6\u3054\u3068\u306bCSS\u306eclass\u3092\u5206\u3051\u308bPHP\u95a2\u6570\u3068\u3001Mac\u304b\u5224\u5225\u3059\u308b\u95a2\u6570\u304c\u5fc5\u8981\u306b\u306a\u3063\u305f\u306e\u3067\u66f8\u304d\u307e\u3057\u305f\u3002<br \/>\n\u3088\u308d\u3057\u3051\u308c\u3070\u3054\u6d3b\u7528\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u30d6\u30e9\u30a6\u30b6\u3054\u3068\u306bclass\u3092\u5206\u3051\u308bPHP\u95a2\u6570<\/h3>\n<p>\u7686\u3055\u3093\u3001\u7279\u5b9a\u306e\u30d6\u30e9\u30a6\u30b6\u3060\u3051\u5fae\u5999\u306b\u30ba\u30ec\u304c\u751f\u3058\u308b\u3068\u304d\u3063\u3066\u3001\u3069\u3046\u3084\u3063\u3066\u5bfe\u5fdc\u3055\u308c\u3066\u307e\u3059\u304b\uff1f<br \/>\n\u79c1\u306fCSS\u306e\u30cf\u30c3\u30af\u306f\u4f7f\u3044\u305f\u304f\u306a\u3044\u306e\u3067\u3001\u666e\u6bb5\u306fIE\u306e\u6761\u4ef6\u5206\u5c90\u30b3\u30e1\u30f3\u30c8\u3067\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u5148\u65e5\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3092HTML5\u3067\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3059\u308b\u3068\u304d\u306b <a href=\"http:\/\/www.w3.org\/html\/logo\/\" target=\"_blank\">HTML5\u30ed\u30b4\u306e\u30da\u30fc\u30b8<\/a> \u306e\u30bd\u30fc\u30b9\u3092\u53c2\u8003\u306b\u3057\u305f\u306e\u3067\u3059\u304c\u3001DOCTYPE\u5ba3\u8a00\u306e\u76f4\u4e0b\u306b\u3053\u3046\u3044\u3046\u3075\u3046\u306b\u66f8\u304b\u308c\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<h4>HTML<\/h4>\n<pre lang=\"html4strict\" line=\"1\">\r\n<!--[if lt IE 7 ]> <html lang=\"en\" class=\"ie6 ielt8\"> <![endif]--> \r\n<!--[if IE 7 ]>    <html lang=\"en\" class=\"ie7 ielt8\"> <![endif]--> \r\n<!--[if IE 8 ]>    <html lang=\"en\" class=\"ie8\"> <![endif]--> \r\n<!--[if (gte IE 9)|!(IE)]><!--> <html lang=\"en\"> <!--<![endif]--> \r\n<\/pre>\n<p>\u306a\u308b\u307b\u3069\u3001IE6\u3060\u3068 ie6 \u3068 ielt8 \u304c\u3001IE7\u3060\u3068 ie7 \u3068 ielt8 \u304c\u3001IE8\u3060\u3068 ie8 \u3068 ielt8 \u304c\u8ffd\u52a0\u3055\u308c\u308b\u306e\u3067\u3001\u4f8b\u3048\u3070IE6\u3060\u3051width\u304c\u304a\u304b\u3057\u3044\u5834\u5408\u306f<\/p>\n<h4>CSS<\/h4>\n<pre lang=\"css\" line=\"1\">\r\n\/* \u5168\u3066\u306e\u30d6\u30e9\u30a6\u30b6\u7528 *\/\r\n.hoge {\r\n\twidth: 300px;\r\n\theight: 100px;\r\n}\r\n\/* IE6\u7528\uff08\u304a\u304b\u3057\u3044\u7b87\u6240\u306e\u5dee\u5206\u3060\u3051\u66f8\u3051\u3070\u826f\u3044\uff09 *\/\r\n.ie6 .hoge {\r\n\twidth: 280px;\r\n}\r\n<\/pre>\n<p>\u3063\u3066\u611f\u3058\u3067\u66f8\u3051\u3070\u826f\u3044\u306e\u3067\u3059\u306d\u3002<br \/>\nIE6\u301c8\u306b\u9069\u7528\u3057\u305f\u3044\u5834\u5408\u306f<\/p>\n<h4>CSS<\/h4>\n<pre lang=\"css\" line=\"1\">\r\n\/* IE6\u301c8\u7528\uff08\u304a\u304b\u3057\u3044\u7b87\u6240\u306e\u5dee\u5206\u3060\u3051\u66f8\u3051\u3070\u826f\u3044\uff09 *\/\r\n.ielt8 .hoge {\r\n\twidth: 280px;\r\n}\r\n<\/pre>\n<p>\u305f\u3060\u3001\u3053\u308c\u3060\u3068IE\u3060\u3051\u306e\u70ba\u306bHTML\u30bd\u30fc\u30b9\u304c\u3054\u3061\u3083\u3064\u3044\u3066\u3057\u307e\u3046\u306e\u3068\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3092\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3057\u3066\u3044\u308b\u6642\u306bFirefox\u3060\u30512px\u305a\u308c\u308b\u7b87\u6240\u304c\u3042\u3063\u305f\uff08Chrome\u3084IE8\u3067\u306f\u305a\u308c\u306a\u3044\uff09\u306e\u3068\u3001iPhone\u3084Android\u3067\u591a\u5c11\u305a\u308c\u308b\u7b87\u6240\u304c\u3042\u3063\u305f\u306e\u3067\u30d6\u30e9\u30a6\u30b6\u3054\u3068\u306bclass\u3092\u5206\u3051\u308bPHP\u95a2\u6570\u3092\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<h4>PHP<\/h4>\n<pre lang=\"php\" line=\"1\">\r\n<?php\r\n\/\/ \u30d6\u30e9\u30a6\u30b6\u5224\u5225\r\nfunction browser_class() {\r\n\r\n\t\/\/ \u30d6\u30e9\u30a6\u30b6\u306e\u7a2e\u985e\u3092\u53d6\u5f97\r\n\t$ua = getenv('HTTP_USER_AGENT');\r\n\r\n\t\/\/ \u53d6\u5f97\u3057\u305f\u7a2e\u985e\u306b\u3088\u3063\u3066\u5224\u5225\r\n\tswitch (true) {\r\n\t\tcase (preg_match('\/MSIE 6\/', $ua)):\r\n\t\t\techo 'ie ie6';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/MSIE 7\/', $ua)):\r\n\t\t\techo 'ie ie7';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/MSIE 8\/', $ua)):\r\n\t\t\techo 'ie ie8';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/MSIE 9\/', $ua)):\r\n\t\t\techo 'ie9';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/Firefox\/', $ua)):\r\n\t\t\techo 'fx';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/iPhone|iPad\/', $ua)):\r\n\t\t\techo 'ip';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/Android\/', $ua)):\r\n\t\t\techo 'an';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/Chrome\/', $ua)):\r\n\t\t\techo 'ch';\r\n\t\t\tbreak;\r\n\t\tcase (preg_match('\/Safari\/', $ua)):\r\n\t\t\techo 'sa';\r\n\t\t\tbreak;\r\n\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>WordPress\u3060\u3063\u305f\u3089\u3053\u308c\u3092\u30c6\u30fc\u30de\u306e functions.php \u306b\u66f8\u304d\u3001\u305d\u308c\u4ee5\u5916\u306e\u30b5\u30a4\u30c8\u3067\u3042\u308c\u3070\u3053\u306e\u95a2\u6570\u304c\u66f8\u304b\u308c\u305fPHP\u30d5\u30a1\u30a4\u30eb\u3092 include \u3057\u3066<\/p>\n<h4>PHP<\/h4>\n<pre lang=\"php\" line=\"1\">\r\n<html dir=\"ltr\" lang=\"ja\" class=\"<?php browser_class() ?>\">\r\n<\/pre>\n<p>\u3068\u3057\u3066\u3042\u3052\u308c\u3070\u3044\u3044\u3067\u3059\u306d\u3002<br \/>\nIE6\u301c8\u306b\u9069\u7528\u3059\u308bclass\u306f .ielt8 \u3067\u306f\u3061\u3087\u3063\u3068\u9577\u3044\u306e\u3067\u3001\u5358\u306b .ie \u3068\u3057\u307e\u3057\u305f\u3002<br \/>\n\u3053\u308c\u3055\u3048\u3042\u308c\u3070\u3001IE6\u301c8\u306e\u5bfe\u5fdc\u3082\u3060\u3044\u3076\u697d\u306b\u306a\u308a\u305d\u3046\u3067\u3059\u306d\u3002<br \/>\n\u307e\u3042\u3001\u3053\u306e\u30d6\u30ed\u30b0\u306fIE6\u30fb7\u306b\u306f\u5bfe\u5fdc\u3057\u307e\u305b\u3093\u304c\u2026<\/p>\n<h3>Mac\u304b\u5224\u5225\u3059\u308b\u95a2\u6570<\/h3>\n<p>\u3042\u3068\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3067Mac\u306e\u5834\u5408\u3060\u3051\u8aad\u307f\u8fbc\u307e\u305b\u305f\u3044JavaScript\u304c\u3042\u3063\u305f\u306e\u3067\u3001Mac\u304b\u3069\u3046\u304b\u3092\u5224\u5225\u3059\u308b\u95a2\u6570\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<br \/>\nMac\u304bWindows\u304b\u3069\u3046\u304b\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30d5\u30a1\u30a4\u30eb\u3092\u5206\u3051\u308b\u5834\u5408\u306b\u3082\u4f7f\u3048\u305d\u3046\u3067\u3059\u306d\u3002<\/p>\n<h4>PHP<\/h4>\n<pre lang=\"php\" line=\"1\">\r\n<?php\r\n\/\/ Mac\u304b\u5224\u5225\r\nfunction is_mac() {\r\n\r\n\t\/\/ UA\u3092\u53d6\u5f97\r\n\t$ua = $_SERVER['HTTP_USER_AGENT'];\r\n\r\n\t\/\/ UA\u306b Macintosh \u304c\u542b\u307e\u308c\u308b\u304b\r\n\tif (preg_match('\/Macintosh\/', $ua)) {\r\n\r\n\t\treturn true;\r\n\r\n\t} else {\r\n\r\n\t\treturn false;\r\n\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>\u4f7f\u7528\u3059\u308b\u969b\u306f<\/p>\n<h4>PHP<\/h4>\n<pre lang=\"php\" line=\"1\">\r\n<?php if ( is_mac() ) { ?>\r\n\t<p>Mac\u306e\u5834\u5408<\/p>\r\n<?php } else { ?>\r\n\t<p>Mac\u4ee5\u5916\uff08Windows\u30fbLinux\u30fbiPhone\u30fbAndroid\u306a\u3069\uff09\u306e\u5834\u5408<\/p>\r\n<?php } ?>\r\n<\/pre>\n<p>\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30d6\u30ed\u30b0\u3092\u30ea\u30cb\u30e5\u30fc\u30a2\u30eb\u3059\u308b\u306b\u3042\u305f\u3063\u3066\u3001\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3092\u697d\u306b\u3059\u308b\u305f\u3081\u306b\u30d6\u30e9\u30a6\u30b6\u3054\u3068\u306bCSS\u306eclass\u3092\u5206\u3051\u308bPHP\u95a2\u6570\u3068\u3001Mac\u304b\u5224\u5225\u3059\u308b\u95a2\u6570\u304c\u5fc5\u8981\u306b\u306a\u3063\u305f\u306e\u3067\u66f8\u304d\u307e\u3057\u305f\u3002 \u3088\u308d\u3057\u3051\u308c\u3070\u3054\u6d3b\u7528\u304f\u3060\u3055\u3044\u3002 \u30d6\u30e9\u30a6\u30b6\u3054\u3068\u306bc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[29,4],"tags":[25,81],"class_list":["post-525","post","type-post","status-publish","format-standard","hentry","category-iphone-mac","category-web","tag-css","tag-mac"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/posts\/525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":0,"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/posts\/525\/revisions"}],"wp:attachment":[{"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/media?parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/categories?post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stocker.jp\/diary\/wp-json\/wp\/v2\/tags?post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}